summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Lidén Borell <samuel@slbdata.se>2010-03-23 23:57:03 +0100
committerSamuel Lidén Borell <samuel@slbdata.se>2010-03-23 23:57:03 +0100
commit1eadbd183a474fe072d7099e1a81f73c5de96774 (patch)
tree65e59b589d824e02cf4355e359993367ac0c0a4f
parenta46d06fe90c5963e9c769e5bbfa6349721e95cc7 (diff)
downloadfribid-1eadbd183a474fe072d7099e1a81f73c5de96774.tar.gz
fribid-1eadbd183a474fe072d7099e1a81f73c5de96774.tar.bz2
fribid-1eadbd183a474fe072d7099e1a81f73c5de96774.zip
Implement the "NonVisibleData" parameter
This parameter works like TextToBeSigned, except that the text is not shown to the user. It's used by Skatteverket (the Swedish Tax Office) to sign XML documents, for instance.
-rw-r--r--client/bankid.c11
-rw-r--r--client/bankid.h2
-rw-r--r--client/main.c9
-rw-r--r--client/misc.c22
-rw-r--r--client/misc.h3
-rw-r--r--common/defines.h4
-rw-r--r--plugin/ipc.c3
-rw-r--r--plugin/plugin.c2
-rw-r--r--plugin/plugin.h5
9 files changed, 49 insertions, 12 deletions
diff --git a/client/bankid.c b/client/bankid.c
index 8cb60b4..0d8d5dd 100644
--- a/client/bankid.c
+++ b/client/bankid.c
@@ -228,6 +228,11 @@ static const char signedText_template[] =
"%s"
"</usrVisibleData>";
+static const char signedInvisibleText_template[] =
+ "<usrNonVisibleData>"
+ "%s"
+ "</usrNonVisibleData>";
+
static const char signobj_id[] = "bidSignedData";
/**
@@ -300,12 +305,16 @@ BankIDError bankid_sign(const char *p12Data, const int p12Length,
const char *password,
const char *challenge,
const char *hostname, const char *ip,
- const char *message,
+ const char *message, const char *invisibleMessage,
char **signature) {
BankIDError error;
char *extra = rasprintf(signedText_template, message);
+ if (invisibleMessage) {
+ extra = rasprintf_append(extra, signedInvisibleText_template, invisibleMessage);
+ }
+
error = sign(p12Data, p12Length, person, password, challenge,
hostname, ip, CERTUSE_SIGNING, "Signing", extra, signature);
diff --git a/client/bankid.h b/client/bankid.h
index a157910..18e3968 100644
--- a/client/bankid.h
+++ b/client/bankid.h
@@ -49,7 +49,7 @@ BankIDError bankid_sign(const char *p12Data, const int p12Length,
const char *password,
const char *challenge,
const char *hostname, const char *ip,
- const char *message,
+ const char *message, const char *invisibleMessage,
char **signature);
#endif
diff --git a/client/main.c b/client/main.c
index 7057b6b..966485d 100644
--- a/client/main.c
+++ b/client/main.c
@@ -53,9 +53,10 @@ void pipeData() {
char *url = pipe_readString(stdin);
char *hostname = pipe_readString(stdin);
char *ip = pipe_readString(stdin);
- char *message = NULL;
+ char *message = NULL, *invisibleMessage = NULL;
if (command == PMC_Sign) {
message = pipe_readString(stdin);
+ invisibleMessage = pipe_readOptionalString(stdin);
}
// Validate input
@@ -68,7 +69,8 @@ void pipeData() {
!is_valid_ip_address(ip) ||
(subjectFilter && !is_canonical_base64(subjectFilter)) ||
(command == PMC_Sign && (
- !is_canonical_base64(message)
+ !is_canonical_base64(message) ||
+ (invisibleMessage && !is_canonical_base64(invisibleMessage))
))) {
error = BIDERR_InternalError;
}
@@ -130,7 +132,7 @@ void pipeData() {
} else {
error = bankid_sign(p12Data, p12Length, person, password,
challenge, hostname, ip,
- message, &signature);
+ message, invisibleMessage, &signature);
}
free(p12Data);
@@ -148,6 +150,7 @@ void pipeData() {
platform_endSign();
free(message);
+ free(invisibleMessage);
free(challenge);
free(url);
free(hostname);
diff --git a/client/misc.c b/client/misc.c
index 08ffa27..4ec22c7 100644
--- a/client/misc.c
+++ b/client/misc.c
@@ -1,6 +1,6 @@
/*
- Copyright (c) 2009 Samuel Lidén Borell <samuel@slbdata.se>
+ Copyright (c) 2009-2010 Samuel Lidén Borell <samuel@slbdata.se>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -46,6 +46,26 @@ char *rasprintf(const char *format, ...) {
}
/**
+ * Like rasprintf (above), but appends to an existing string instead of
+ * creating a new one. The original string is reallocated as a longer
+ * string, which is returned.
+ */
+char *rasprintf_append(char *str, const char *format, ...) {
+ va_list args;
+
+ size_t oldlen = strlen(str);
+ va_start(args, format);
+ char *tail = (char*)g_strdup_vprintf((gchar*)format, args);
+ va_end(args);
+ size_t taillen = strlen(tail);
+
+ str = realloc(str, oldlen+taillen+1);
+ memcpy(&str[oldlen], tail, taillen+1);
+ free(tail);
+ return str;
+}
+
+/**
* This is a modified memset(3) function to cover the
* problems documented by David Wheeler in:
* http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/\
diff --git a/client/misc.h b/client/misc.h
index be6e399..64d69a4 100644
--- a/client/misc.h
+++ b/client/misc.h
@@ -1,6 +1,6 @@
/*
- Copyright (c) 2009 Samuel Lidén Borell <samuel@slbdata.se>
+ Copyright (c) 2009-2010 Samuel Lidén Borell <samuel@slbdata.se>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -28,6 +28,7 @@
#include <stdbool.h>
char *rasprintf(const char *format, ...);
+char *rasprintf_append(char *str, const char *format, ...);
void *guaranteed_memset(void *v, int c, size_t n);
char *base64_encode(const char *data, const int length);
diff --git a/common/defines.h b/common/defines.h
index 4a1128c..6075934 100644
--- a/common/defines.h
+++ b/common/defines.h
@@ -1,6 +1,6 @@
/*
- Copyright (c) 2009 Samuel Lidén Borell <samuel@slbdata.se>
+ Copyright (c) 2009-2010 Samuel Lidén Borell <samuel@slbdata.se>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -32,7 +32,7 @@
#define BINNAME "fribid"
#define RELEASE_TIME 1266675990
-#define IPCVERSION "2"
+#define IPCVERSION "3"
#define EMULATED_VERSION "4.10.2.16"
#define DNSVERSION "1"
diff --git a/plugin/ipc.c b/plugin/ipc.c
index 3d618f2..36416e0 100644
--- a/plugin/ipc.c
+++ b/plugin/ipc.c
@@ -1,6 +1,6 @@
/*
- Copyright (c) 2009 Samuel Lidén Borell <samuel@slbdata.se>
+ Copyright (c) 2009-2010 Samuel Lidén Borell <samuel@slbdata.se>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -157,6 +157,7 @@ int sign_performAction_Sign(Plugin *plugin) {
sendSignCommon(pipeinfo, plugin);
pipe_sendString(pipeinfo.out, plugin->info.sign.message);
+ pipe_sendOptionalString(pipeinfo.out, plugin->info.sign.invisibleMessage);
pipe_finishCommand(pipeinfo.out);
diff --git a/plugin/plugin.c b/plugin/plugin.c
index 322f6be..386d3db 100644
--- a/plugin/plugin.c
+++ b/plugin/plugin.c
@@ -69,6 +69,7 @@ void plugin_free(Plugin *plugin) {
free(plugin->info.sign.policys);
free(plugin->info.sign.subjectFilter);
free(plugin->info.sign.message);
+ free(plugin->info.sign.invisibleMessage);
free(plugin->info.sign.signature);
break;
}
@@ -124,6 +125,7 @@ static char **getParamPointer(Plugin *plugin, const char *name) {
case PT_Signer:
if (!strcmp(name, "Nonce")) return &plugin->info.sign.challenge;
if (!strcmp(name, "TextToBeSigned")) return &plugin->info.sign.message;
+ if (!strcmp(name, "NonVisibleData")) return &plugin->info.sign.invisibleMessage;
return getCommonParamPointer(plugin, name);
default:
return NULL;
diff --git a/plugin/plugin.h b/plugin/plugin.h
index 05ccd38..ac78e90 100644
--- a/plugin/plugin.h
+++ b/plugin/plugin.h
@@ -1,6 +1,6 @@
/*
- Copyright (c) 2009 Samuel Lidén Borell <samuel@slbdata.se>
+ Copyright (c) 2009-2010 Samuel Lidén Borell <samuel@slbdata.se>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -53,7 +53,7 @@ typedef struct {
char *challenge;
char *policys;
char *subjectFilter;
- void *dummy0; // To be compatible with .sign below
+ void *dummy0, *dummy1; // To be compatible with .sign below
/* Output parameters */
char *signature;
} auth;
@@ -63,6 +63,7 @@ typedef struct {
char *policys;
char *subjectFilter;
char *message;
+ char *invisibleMessage;
/* Output parameters */
char *signature;
} sign;