summaryrefslogtreecommitdiff
path: root/client/bankid.c
diff options
context:
space:
mode:
authorSamuel Lidén Borell <samuel@slbdata.se>2010-06-08 17:55:11 +0200
committerSamuel Lidén Borell <samuel@slbdata.se>2010-06-08 18:37:22 +0200
commit50172850038388c92ecd998ed3c815d3b8a080cb (patch)
treefe1d824c45f8f55992354906b83f7d899539f064 /client/bankid.c
parent0bb1bb4e2aaec96fd63e67fcc938bc6c92ed39ff (diff)
downloadfribid-50172850038388c92ecd998ed3c815d3b8a080cb.tar.gz
fribid-50172850038388c92ecd998ed3c815d3b8a080cb.tar.bz2
fribid-50172850038388c92ecd998ed3c815d3b8a080cb.zip
Use the built-in expiry and emulated version after upgrades
Diffstat (limited to 'client/bankid.c')
-rw-r--r--client/bankid.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/client/bankid.c b/client/bankid.c
index 0d8d5dd..d761153 100644
--- a/client/bankid.c
+++ b/client/bankid.c
@@ -118,6 +118,20 @@ static bool checkValidity(bool *valid, char **versionToEmulate) {
return true;
}
+
+static void storeExpiryParameters(PlatformConfig *cfg,
+ int64_t lastCheck, bool valid,
+ const char *emulatedVersion) {
+ if (valid) {
+ platform_setConfigInteger(cfg, "expiry", "best-before",
+ lastCheck - EXPIRY_RAND + 30*24*3600);
+ }
+ platform_setConfigBool(cfg, "expiry", "still-valid", valid);
+ platform_setConfigString(cfg, "expiry", "version-to-emulate", emulatedVersion);
+ platform_setConfigString(cfg, "expiry", "checked-with-version", DNSVERSION);
+ platform_saveConfig(cfg);
+}
+
/**
* Checks the validity of the emulated version and stores the status
* in the configuration file.
@@ -128,14 +142,8 @@ static void versionCheckFunction(void *ignored) {
char *versionToEmulate;
if (checkValidity(&valid, &versionToEmulate)) {
- if (valid) {
- platform_setConfigInteger(cfg, "expiry", "best-before",
- time(NULL) - EXPIRY_RAND + 30*24*3600);
- }
- platform_setConfigBool(cfg, "expiry", "still-valid", valid);
- platform_setConfigString(cfg, "expiry", "version-to-emulate", versionToEmulate);
- platform_setConfigString(cfg, "expiry", "checked-with-version", DNSVERSION);
- platform_saveConfig(cfg);
+ storeExpiryParameters(cfg, time(NULL), valid,
+ versionToEmulate);
free(versionToEmulate);
}
@@ -151,6 +159,17 @@ static void versionCheckFunction(void *ignored) {
void bankid_checkVersionValidity() {
PlatformConfig *cfg = platform_openConfig(BINNAME, "expiry");
+ char *checkedWithVersion = NULL;
+ if (platform_getConfigString(cfg, "expiry", "checked-with-version", &checkedWithVersion) &&
+ strcmp(checkedWithVersion, DNSVERSION) != 0) {
+ // The last check was done with another version, so overwrite the
+ // old configuration with the defaults
+ storeExpiryParameters(cfg, DEFAULT_EXPIRY, true,
+ defaultEmulatedVersion);
+
+ }
+ free(checkedWithVersion);
+
long lexpiry;
time_t expiry;
if (platform_getConfigInteger(cfg, "expiry", "best-before", &lexpiry)) {
@@ -164,16 +183,6 @@ void bankid_checkVersionValidity() {
maybeValid = true;
}
- char *checkedWithVersion = NULL;
- if (!platform_getConfigString(cfg, "expiry", "checked-with-version", &checkedWithVersion)) {
- maybeValid = true;
- } else if (strcmp(checkedWithVersion, DNSVERSION) != 0) {
- // The check was done with another version, so the current version
- // might not have expired even if the old version has expired.
- maybeValid = true;
- }
- free(checkedWithVersion);
-
platform_freeConfig(cfg);
// Check the expiry