summaryrefslogtreecommitdiff
path: root/client/bankid.c
diff options
context:
space:
mode:
authorSamuel Lidén Borell <samuel@slbdata.se>2012-04-06 18:43:08 +0200
committerSamuel Lidén Borell <samuel@slbdata.se>2012-04-06 18:43:08 +0200
commitb8ac887506c75a3c8960873d3cb6297c5d120114 (patch)
treec13677d494b276e43ab21747a4ceec702a21c822 /client/bankid.c
parent289a90a1ceded15ed8de122f80178be3dd130cb5 (diff)
downloadfribid-b8ac887506c75a3c8960873d3cb6297c5d120114.tar.gz
fribid-b8ac887506c75a3c8960873d3cb6297c5d120114.tar.bz2
fribid-b8ac887506c75a3c8960873d3cb6297c5d120114.zip
Make version-to-emulate configurable in ~/.config/fribid/config
This file is never overwritten automatically, unlike ~/.config/fribid/expiry
Diffstat (limited to 'client/bankid.c')
-rw-r--r--client/bankid.c49
1 files changed, 32 insertions, 17 deletions
diff --git a/client/bankid.c b/client/bankid.c
index 319e68f..aaf02c9 100644
--- a/client/bankid.c
+++ b/client/bankid.c
@@ -36,8 +36,7 @@
#include "misc.h"
#include "bankid.h"
#include "platform.h"
-
-static const char defaultEmulatedVersion[] = EMULATED_VERSION;
+#include "prefs.h"
#define EXPIRY_RAND (rand() % 65535)
#define DEFAULT_EXPIRY (RELEASE_TIME + 30*24*3600)
@@ -70,26 +69,36 @@ static char *getVersionString() {
long lexpiry;
int64_t expiry;
- char *versionToEmulate;
-
- PlatformConfig *cfg = platform_openConfig(BINNAME, "expiry");
+ const char *versionToEmulate;
+ bool allocated = false;
- if (platform_getConfigInteger(cfg, "expiry", "best-before", &lexpiry)) {
- expiry = lexpiry;
+ if (prefs_bankid_emulatedversion) {
+ /* Manual override */
+ versionToEmulate = prefs_bankid_emulatedversion;
+ expiry = time(NULL) + 30*24*3600;
} else {
- expiry = DEFAULT_EXPIRY;
- }
-
- if (!platform_getConfigString(cfg, "expiry", "version-to-emulate", &versionToEmulate)) {
- versionToEmulate = (char *)defaultEmulatedVersion;
+ /* Use automatic version from DNS */
+ PlatformConfig *cfg = platform_openConfig(BINNAME, "expiry");
+
+ if (platform_getConfigInteger(cfg, "expiry", "best-before", &lexpiry)) {
+ expiry = lexpiry;
+ } else {
+ expiry = DEFAULT_EXPIRY;
+ }
+
+ if (platform_getConfigString(cfg, "expiry", "version-to-emulate", (char**)&versionToEmulate)) {
+ allocated = true;
+ } else {
+ versionToEmulate = EMULATED_VERSION;
+ }
+
+ platform_freeConfig(cfg);
}
- platform_freeConfig(cfg);
-
char *result = rasprintf(template, versionToEmulate, expiry);
- if (versionToEmulate != defaultEmulatedVersion) {
- free(versionToEmulate);
+ if (allocated) {
+ free((char*)versionToEmulate);
}
return result;
}
@@ -165,6 +174,9 @@ static void versionCheckFunction(void *ignored) {
* need checking within 14 days, then the check will be asynchronous.
*/
void bankid_checkVersionValidity() {
+ if (prefs_bankid_emulatedversion)
+ return;
+
PlatformConfig *cfg = platform_openConfig(BINNAME, "expiry");
char *checkedWithVersion = NULL;
@@ -173,7 +185,7 @@ void bankid_checkVersionValidity() {
// The last check was done with another version, so overwrite the
// old configuration with the defaults
storeExpiryParameters(cfg, DEFAULT_EXPIRY, true,
- defaultEmulatedVersion);
+ EMULATED_VERSION);
}
free(checkedWithVersion);
@@ -207,6 +219,9 @@ void bankid_checkVersionValidity() {
}
bool bankid_versionHasExpired() {
+ if (prefs_bankid_emulatedversion)
+ return false;
+
PlatformConfig *cfg = platform_openConfig(BINNAME, "expiry");
bool valid;