Blame SOURCES/libfido2-openssl30.patch

980fa6
diff --git a/src/assert.c b/src/assert.c
980fa6
index b4f9dd0..d0950a7 100644
980fa6
--- a/src/assert.c
980fa6
+++ b/src/assert.c
980fa6
@@ -363,7 +363,11 @@ fido_get_signed_hash(int cose_alg, fido_blob_t *dgst,
980fa6
 	unsigned char		*authdata_ptr = NULL;
980fa6
 	size_t			 authdata_len;
980fa6
 	struct cbor_load_result	 cbor;
980fa6
+#if OPENSSL_VERSION_NUMBER < 0x30000000
980fa6
 	SHA256_CTX		 ctx;
980fa6
+#else
980fa6
+	EVP_MD_CTX		*mdctx = NULL;
980fa6
+#endif
980fa6
 	int			 ok = -1;
980fa6
 
980fa6
 	if ((item = cbor_load(authdata_cbor->ptr, authdata_cbor->len,
980fa6
@@ -377,10 +381,20 @@ fido_get_signed_hash(int cose_alg, fido_blob_t *dgst,
980fa6
 	authdata_len = cbor_bytestring_length(item);
980fa6
 
980fa6
 	if (cose_alg != COSE_EDDSA) {
980fa6
-		if (dgst->len < SHA256_DIGEST_LENGTH || SHA256_Init(&ctx) == 0 ||
980fa6
+		if (dgst->len < SHA256_DIGEST_LENGTH ||
980fa6
+#if OPENSSL_VERSION_NUMBER < 0x30000000
980fa6
+		    SHA256_Init(&ctx) == 0 ||
980fa6
 		    SHA256_Update(&ctx, authdata_ptr, authdata_len) == 0 ||
980fa6
 		    SHA256_Update(&ctx, clientdata->ptr, clientdata->len) == 0 ||
980fa6
-		    SHA256_Final(dgst->ptr, &ctx) == 0) {
980fa6
+		    SHA256_Final(dgst->ptr, &ctx) == 0
980fa6
+#else
980fa6
+		    (mdctx = EVP_MD_CTX_new()) == NULL ||
980fa6
+		    EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL) <= 0 ||
980fa6
+		    EVP_DigestUpdate(mdctx, authdata_ptr, authdata_len) <= 0 ||
980fa6
+		    EVP_DigestUpdate(mdctx, clientdata->ptr, clientdata->len) <= 0 ||
980fa6
+		    EVP_DigestFinal_ex(mdctx, dgst->ptr, NULL) <= 0
980fa6
+#endif
980fa6
+		    ) {
980fa6
 			fido_log_debug("%s: sha256", __func__);
980fa6
 			goto fail;
980fa6
 		}
980fa6
@@ -406,6 +415,9 @@ fido_get_signed_hash(int cose_alg, fido_blob_t *dgst,
980fa6
 fail:
980fa6
 	if (item != NULL)
980fa6
 		cbor_decref(&item);
980fa6
+#if OPENSSL_VERSION_NUMBER >= 0x30000000
980fa6
+	EVP_MD_CTX_free(mdctx);
980fa6
+#endif
980fa6
 
980fa6
 	return (ok);
980fa6
 }
980fa6
@@ -410,7 +424,11 @@ fido_verify_sig_es256(const fido_blob_t *dgst, const es256_pk_t *pk,
980fa6
     const fido_blob_t *sig)
980fa6
 {
980fa6
 	EVP_PKEY	*pkey = NULL;
980fa6
+#if OPENSSL_VERSION_NUMBER >= 0x30000000
980fa6
+	EVP_PKEY_CTX	*pctx = NULL;
980fa6
+#else
980fa6
 	EC_KEY		*ec = NULL;
980fa6
+#endif
980fa6
 	int		 ok = -1;
980fa6
 
980fa6
 	/* ECDSA_verify needs ints */
980fa6
@@ -420,6 +438,20 @@ fido_verify_sig_es256(const fido_blob_t *dgst, const es256_pk_t *pk,
980fa6
 		return (-1);
980fa6
 	}
980fa6
 
980fa6
+#if OPENSSL_VERSION_NUMBER >= 0x30000000
980fa6
+	if ((pkey = es256_pk_to_EVP_PKEY(pk)) == NULL ||
980fa6
+	    (pctx = EVP_PKEY_CTX_new(pkey, NULL)) == NULL) {
980fa6
+		fido_log_debug("%s: pk -> ec", __func__);
980fa6
+		goto fail;
980fa6
+	}
980fa6
+
980fa6
+	if (EVP_PKEY_verify_init(pctx) != 1 ||
980fa6
+	    EVP_PKEY_verify(pctx, sig->ptr, sig->len,
980fa6
+	    dgst->ptr, dgst->len) != 1) {
980fa6
+		fido_log_debug("%s: EVP_PKEY_verify", __func__);
980fa6
+		goto fail;
980fa6
+	}
980fa6
+#else
980fa6
 	if ((pkey = es256_pk_to_EVP_PKEY(pk)) == NULL ||
980fa6
 	    (ec = EVP_PKEY_get0_EC_KEY(pkey)) == NULL) {
980fa6
 		fido_log_debug("%s: pk -> ec", __func__);
980fa6
@@ -433,10 +465,13 @@ fido_verify_sig_es256(const fido_blob_t *dgst, const es256_pk_t *pk,
980fa6
 	}
980fa6
 
980fa6
 	ok = 0;
980fa6
+#endif
980fa6
 fail:
980fa6
 	if (pkey != NULL)
980fa6
 		EVP_PKEY_free(pkey);
980fa6
-
980fa6
+#if OPENSSL_VERSION_NUMBER >= 0x30000000
980fa6
+	EVP_PKEY_CTX_free(pctx);
980fa6
+#endif
980fa6
 	return (ok);
980fa6
 }
980fa6
 
980fa6
@@ -445,7 +480,11 @@ fido_verify_sig_rs256(const fido_blob_t *dgst, const rs256_pk_t *pk,
980fa6
     const fido_blob_t *sig)
980fa6
 {
980fa6
 	EVP_PKEY	*pkey = NULL;
980fa6
+#if OPENSSL_VERSION_NUMBER >= 0x30000000
980fa6
+	EVP_PKEY_CTX	*pctx = NULL;
980fa6
+#else
980fa6
 	RSA		*rsa = NULL;
980fa6
+#endif
980fa6
 	int		 ok = -1;
980fa6
 
980fa6
 	/* RSA_verify needs unsigned ints */
980fa6
@@ -455,6 +494,22 @@ fido_verify_sig_rs256(const fido_blob_t *dgst, const rs256_pk_t *pk,
980fa6
 		return (-1);
980fa6
 	}
980fa6
 
980fa6
+#if OPENSSL_VERSION_NUMBER >= 0x30000000
980fa6
+	if ((pkey = rs256_pk_to_EVP_PKEY(pk)) == NULL ||
980fa6
+	    (pctx = EVP_PKEY_CTX_new(pkey, NULL)) == NULL) {
980fa6
+		fido_log_debug("%s: pk -> ec", __func__);
980fa6
+		goto fail;
980fa6
+	}
980fa6
+
980fa6
+	if (EVP_PKEY_verify_init(pctx) != 1 ||
980fa6
+	    EVP_PKEY_CTX_set_rsa_padding(pctx, RSA_PKCS1_PADDING) != 1 ||
980fa6
+	    EVP_PKEY_CTX_set_signature_md(pctx, EVP_sha256()) != 1 ||
980fa6
+	    EVP_PKEY_verify(pctx, sig->ptr, sig->len,
980fa6
+	    dgst->ptr, dgst->len) != 1) {
980fa6
+		fido_log_debug("%s: EVP_PKEY_verify", __func__);
980fa6
+		goto fail;
980fa6
+	}
980fa6
+#else
980fa6
 	if ((pkey = rs256_pk_to_EVP_PKEY(pk)) == NULL ||
980fa6
 	    (rsa = EVP_PKEY_get0_RSA(pkey)) == NULL) {
980fa6
 		fido_log_debug("%s: pk -> ec", __func__);
980fa6
@@ -466,12 +521,16 @@ fido_verify_sig_rs256(const fido_blob_t *dgst, const rs256_pk_t *pk,
980fa6
 		fido_log_debug("%s: RSA_verify", __func__);
980fa6
 		goto fail;
980fa6
 	}
980fa6
+#endif
980fa6
 
980fa6
 	ok = 0;
980fa6
 fail:
980fa6
 	if (pkey != NULL)
980fa6
 		EVP_PKEY_free(pkey);
980fa6
 
980fa6
+#if OPENSSL_VERSION_NUMBER >= 0x30000000
980fa6
+	EVP_PKEY_CTX_free(pctx);
980fa6
+#endif
980fa6
 	return (ok);
980fa6
 }
980fa6
 
980fa6
diff --git a/src/cred.c b/src/cred.c
980fa6
index 92efde4..2ba1dd9 100644
980fa6
--- a/src/cred.c
980fa6
+++ b/src/cred.c
980fa6
@@ -247,7 +247,11 @@ verify_sig(const fido_blob_t *dgst, const fido_blob_t *x5c,
980fa6
 	BIO		*rawcert = NULL;
980fa6
 	X509		*cert = NULL;
980fa6
 	EVP_PKEY	*pkey = NULL;
980fa6
-	EC_KEY		*ec;
980fa6
+#if OPENSSL_VERSION_NUMBER >= 0x30000000
980fa6
+	EVP_PKEY_CTX	*pctx = NULL;
980fa6
+#else
980fa6
+	EC_KEY		*ec = NULL;
980fa6
+#endif
980fa6
 	int		 ok = -1;
980fa6
 
980fa6
 	/* openssl needs ints */
980fa6
@@ -257,6 +261,22 @@ verify_sig(const fido_blob_t *dgst, const fido_blob_t *x5c,
980fa6
 		return (-1);
980fa6
 	}
980fa6
 
980fa6
+#if OPENSSL_VERSION_NUMBER >= 0x30000000
980fa6
+	if ((rawcert = BIO_new_mem_buf(x5c->ptr, (int)x5c->len)) == NULL ||
980fa6
+	    (cert = d2i_X509_bio(rawcert, NULL)) == NULL ||
980fa6
+	    (pkey = X509_get_pubkey(cert)) == NULL ||
980fa6
+	    (pctx = EVP_PKEY_CTX_new(pkey, NULL)) == NULL) {
980fa6
+		fido_log_debug("%s: x509 key", __func__);
980fa6
+		goto fail;
980fa6
+	}
980fa6
+
980fa6
+	if (EVP_PKEY_verify_init(pctx) != 1 ||
980fa6
+	    EVP_PKEY_verify(pctx, sig->ptr, sig->len,
980fa6
+	    dgst->ptr, dgst->len) != 1) {
980fa6
+		fido_log_debug("%s: EVP_PKEY_verify", __func__);
980fa6
+		goto fail;
980fa6
+	}
980fa6
+#else
980fa6
 	/* fetch key from x509 */
980fa6
 	if ((rawcert = BIO_new_mem_buf(x5c->ptr, (int)x5c->len)) == NULL ||
980fa6
 	    (cert = d2i_X509_bio(rawcert, NULL)) == NULL ||
980fa6
@@ -271,6 +291,7 @@ verify_sig(const fido_blob_t *dgst, const fido_blob_t *x5c,
980fa6
 		fido_log_debug("%s: ECDSA_verify", __func__);
980fa6
 		goto fail;
980fa6
 	}
980fa6
+#endif
980fa6
 
980fa6
 	ok = 0;
980fa6
 fail:
980fa6
@@ -280,6 +301,9 @@ fail:
980fa6
 		X509_free(cert);
980fa6
 	if (pkey != NULL)
980fa6
 		EVP_PKEY_free(pkey);
980fa6
+#if OPENSSL_VERSION_NUMBER >= 0x30000000
980fa6
+	EVP_PKEY_CTX_free(pctx);
980fa6
+#endif
980fa6
 
980fa6
 	return (ok);
980fa6
 }
980fa6
--- libfido2-1.6.0/CMakeLists.txt.orig	2021-05-25 16:26:28.124822909 +0200
980fa6
+++ libfido2-1.6.0/CMakeLists.txt	2021-05-25 16:27:08.492148194 +0200
980fa6
@@ -152,6 +152,7 @@
980fa6
 	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-stringop-overflow")
980fa6
 	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic")
980fa6
 	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic-errors")
980fa6
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
980fa6
 	check_c_compiler_flag("-fstack-protector-all" HAVE_STACK_PROTECTOR_ALL)
980fa6
 	if(HAVE_STACK_PROTECTOR_ALL)
980fa6
 		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all")