/*
* make_keylist - generate key list
*
+ * Returns
+ * XEVNT_OK success
+ * XEVNT_PER host certificate expired
+ *
* This routine constructs a pseudo-random sequence by repeatedly
* hashing the session key starting from a given source address,
* destination address, private value and the next key ID of the
* preceeding session key. The last entry on the list is saved along
* with its sequence number and public signature.
*/
-void
+int
make_keylist(
struct peer *peer, /* peer structure pointer */
struct interface *dstadr /* interface */
vp->fstamp = hostval.tstamp;
vp->vallen = htonl(sizeof(struct autokey));
vp->siglen = 0;
- if (vp->tstamp != 0) {
+ if (tstamp != 0) {
+ if (tstamp < cinfo->first || tstamp > cinfo->last)
+ return (XEVNT_PER);
+
if (vp->sig == NULL)
vp->sig = emalloc(sign_siglen);
EVP_SignInit(&ctx, sign_digest);
ntohl(ap->seq), ntohl(ap->key), cookie,
ntohl(vp->tstamp), ntohl(vp->fstamp), peer->hpoll);
#endif
+ return (XEVNT_OK);
}
strcpy(peer->issuer, cinfo->issuer);
/*
- * We plug in the public key and group key in
+ * We plug in the public key and lifetime from
* the first certificate received. However, note
* that this certificate might not be signed by
* the server, so we can't check the
X509_free(cert);
peer->first = cinfo->first;
peer->last = cinfo->last;
+ } else if (max(peer->first, cinfo->first) <
+ min(peer->last, cinfo->last)) {
+ peer->flags |= CRYPTO_FLAG_INVLD;
+ sprintf(statstr,
+ "broken server certificate trail %s->%s",
+ cinfo->issuer, cinfo->subject);
+ record_crypto_stats(&peer->srcadr,
+ statstr);
+ report_event(XEVNT_SRV, peer);
+#ifdef DEBUG
+ if (debug)
+ printf("crypto_recv: %s\n",
+ statstr);
+#endif
}
+ peer->cfirst = cinfo->first;
+ peer->clast = cinfo->last;
peer->flash &= ~TEST8;
temp32 = cinfo->nid;
sprintf(statstr, "cert %s 0x%x %s (%u) fs %u",
* XEVNT_PUB bad or missing public key
* XEVNT_SGL bad signature length
* XEVNT_SIG signature not verified
- * XEVNT_PER certificate expired
* XEVNT_ERR protocol error
+ * XEVNT_SRV server certificate expired
*/
static int
crypto_verify(
} else if (siglen != (u_int)EVP_PKEY_size(pkey)) {
rval = XEVNT_SGL;
- } else if (tstamp < peer->first || tstamp > peer->last){
- rval = XEVNT_PER;
} else {
+ tstamp = crypto_time();
+ if (peer->flags & CRYPTO_FLAG_INVLD || tstamp <
+ peer->first || tstamp > peer->last)
+ return (XEVNT_SRV);
+
EVP_VerifyInit(&ctx, peer->digest);
EVP_VerifyUpdate(&ctx, (u_char *)&ep->tstamp, vallen +
12);
* XEVNT_OK success
* XEVNT_PUB bad or missing public key
* XEVNT_CKY bad or missing cookie
+ * XEVNT_PER host certificate expired
*/
static int
crypto_encrypt(
if (tstamp == 0)
return (XEVNT_OK);
+ if (tstamp < cinfo->first || tstamp > cinfo->last)
+ return (XEVNT_PER);
+
vp->sig = emalloc(sign_siglen);
EVP_SignInit(&ctx, sign_digest);
EVP_SignUpdate(&ctx, (u_char *)&vp->tstamp, 12);
if ((tstamp = crypto_time()) == 0)
return;
+ if (tstamp < cinfo->first || tstamp > cinfo->last) {
+ msyslog(
+ LOG_ERR, "crypto_update: expired certificate\n");
+ return;
+ }
hostval.tstamp = htonl(tstamp);
/*
if (tstamp == 0)
return (XEVNT_OK);
+ if (tstamp < cinfo->first || tstamp > cinfo->last)
+ return (XEVNT_PER);
+
vp->sig = emalloc(sign_siglen);
EVP_SignInit(&ctx, sign_digest);
EVP_SignUpdate(&ctx, (u_char *)&vp->tstamp, 12);
* XEVNT_OK success
* XEVNT_ID bad or missing group key
* XEVNT_ERR protocol error
+ * XEVNT_PER host expired certificate
*/
static int
crypto_bob(
if (tstamp == 0)
return (XEVNT_OK);
+ if (tstamp < cinfo->first || tstamp > cinfo->last)
+ return (XEVNT_PER);
+
vp->sig = emalloc(sign_siglen);
EVP_SignInit(&ctx, sign_digest);
EVP_SignUpdate(&ctx, (u_char *)&vp->tstamp, 12);
* XEVNT_OK success
* XEVNT_PUB bad or missing public key
* XEVNT_ID bad or missing group key
+ * XEVNT_PER host certificate expired
*/
static int
crypto_alice2(
if (tstamp == 0)
return (XEVNT_OK);
+ if (tstamp < cinfo->first || tstamp > cinfo->last)
+ return (XEVNT_PER);
+
vp->sig = emalloc(sign_siglen);
EVP_SignInit(&ctx, sign_digest);
EVP_SignUpdate(&ctx, (u_char *)&vp->tstamp, 12);
* XEVNT_OK success
* XEVNT_ID bad or missing group key
* XEVNT_ERR protocol error
+ * XEVNT_PER host certificate expired
*/
static int
crypto_bob2(
if (tstamp == 0)
return (XEVNT_OK);
+ if (tstamp < cinfo->first || tstamp > cinfo->last)
+ return (XEVNT_PER);
+
vp->sig = emalloc(sign_siglen);
EVP_SignInit(&ctx, sign_digest);
EVP_SignUpdate(&ctx, (u_char *)&vp->tstamp, 12);
* XEVNT_OK success
* XEVNT_PUB bad or missing public key
* XEVNT_ID bad or missing group key
+ * XEVNT_PER host certificate expired
*/
static int
crypto_alice3(
if (tstamp == 0)
return (XEVNT_OK);
+ if (tstamp < cinfo->first || tstamp > cinfo->last)
+ return (XEVNT_PER);
+
vp->sig = emalloc(sign_siglen);
EVP_SignInit(&ctx, sign_digest);
EVP_SignUpdate(&ctx, (u_char *)&vp->tstamp, 12);
* Returns
* XEVNT_OK success
* XEVNT_ERR protocol error
+ * XEVNT_PER host certificate expired
*/
static int
crypto_bob3(
if (tstamp == 0)
return (XEVNT_OK);
+ if (tstamp < cinfo->first || tstamp > cinfo->last)
+ return (XEVNT_PER);
+
vp->sig = emalloc(sign_siglen);
EVP_SignInit(&ctx, sign_digest);
EVP_SignUpdate(&ctx, (u_char *)&vp->tstamp, 12);
* serial number, issuer name and validity interval of the server. The
* validity interval extends from the current time to the same time one
* year hence. For NTP purposes, it is convenient to use the NTP seconds
- * of the current time as the serial number.
+ * of the current time as the serial number. By default, the valid
+ * period is one year.
*
* Returns
* XEVNT_OK success
* XEVNT_PUB bad or missing public key
* XEVNT_CRT bad or missing certificate
* XEVNT_VFY certificate not verified
+ * XEVNT_PER host certificate expired
*/
static int
cert_sign(
if (tstamp == 0)
return (XEVNT_TSP);
+ if (tstamp < cinfo->first || tstamp > cinfo->last)
+ return (XEVNT_PER);
+
ptr = (u_char *)ep->pkt;
if ((req = d2i_X509(NULL, &ptr, ntohl(ep->vallen))) == NULL) {
msyslog(LOG_ERR, "cert_sign %s\n",