2016-05-17 18:52:22 +00:00
|
|
|
/*
|
2018-03-20 13:00:17 +00:00
|
|
|
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 10:52:47 +00:00
|
|
|
*
|
2018-12-06 13:00:36 +00:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-17 18:52:22 +00:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1998-12-21 10:52:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 14:56:48 +00:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-23 22:13:45 +00:00
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/objects.h>
|
|
|
|
#include <openssl/x509.h>
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2016-08-17 13:58:56 +00:00
|
|
|
int X509_certificate_type(const X509 *x, const EVP_PKEY *pkey)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2016-08-17 12:50:48 +00:00
|
|
|
const EVP_PKEY *pk;
|
2015-01-22 03:40:55 +00:00
|
|
|
int ret = 0, i;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (x == NULL)
|
2017-10-17 14:04:09 +00:00
|
|
|
return 0;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (pkey == NULL)
|
2015-12-20 00:32:36 +00:00
|
|
|
pk = X509_get0_pubkey(x);
|
2015-01-22 03:40:55 +00:00
|
|
|
else
|
|
|
|
pk = pkey;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (pk == NULL)
|
2017-10-17 14:04:09 +00:00
|
|
|
return 0;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2016-01-19 00:21:12 +00:00
|
|
|
switch (EVP_PKEY_id(pk)) {
|
2015-01-22 03:40:55 +00:00
|
|
|
case EVP_PKEY_RSA:
|
|
|
|
ret = EVP_PK_RSA | EVP_PKT_SIGN;
|
|
|
|
/* if (!sign only extension) */
|
|
|
|
ret |= EVP_PKT_ENC;
|
2018-06-06 21:28:13 +00:00
|
|
|
break;
|
|
|
|
case EVP_PKEY_RSA_PSS:
|
|
|
|
ret = EVP_PK_RSA | EVP_PKT_SIGN;
|
2015-01-22 03:40:55 +00:00
|
|
|
break;
|
|
|
|
case EVP_PKEY_DSA:
|
|
|
|
ret = EVP_PK_DSA | EVP_PKT_SIGN;
|
|
|
|
break;
|
|
|
|
case EVP_PKEY_EC:
|
|
|
|
ret = EVP_PK_EC | EVP_PKT_SIGN | EVP_PKT_EXCH;
|
|
|
|
break;
|
2018-02-28 14:59:44 +00:00
|
|
|
case EVP_PKEY_ED448:
|
2017-06-20 15:32:44 +00:00
|
|
|
case EVP_PKEY_ED25519:
|
2017-05-24 20:52:31 +00:00
|
|
|
ret = EVP_PKT_SIGN;
|
|
|
|
break;
|
2015-01-22 03:40:55 +00:00
|
|
|
case EVP_PKEY_DH:
|
|
|
|
ret = EVP_PK_DH | EVP_PKT_EXCH;
|
|
|
|
break;
|
|
|
|
case NID_id_GostR3410_2001:
|
2015-11-17 15:32:30 +00:00
|
|
|
case NID_id_GostR3410_2012_256:
|
|
|
|
case NID_id_GostR3410_2012_512:
|
2015-01-22 03:40:55 +00:00
|
|
|
ret = EVP_PKT_EXCH | EVP_PKT_SIGN;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
? crypto/aes/aes-armv4.S
? crypto/aes/aesni-sha1-x86_64.s
? crypto/aes/aesni-x86_64.s
? crypto/aes/foo.pl
? crypto/aes/vpaes-x86_64.s
? crypto/bn/.bn_lib.c.swp
? crypto/bn/armv4-gf2m.S
? crypto/bn/diffs
? crypto/bn/modexp512-x86_64.s
? crypto/bn/x86_64-gf2m.s
? crypto/bn/x86_64-mont5.s
? crypto/ec/bc.txt
? crypto/ec/diffs
? crypto/modes/a.out
? crypto/modes/diffs
? crypto/modes/ghash-armv4.S
? crypto/modes/ghash-x86_64.s
? crypto/modes/op.h
? crypto/modes/tst.c
? crypto/modes/x.h
? crypto/objects/.obj_xref.txt.swp
? crypto/rand/diffs
? crypto/sha/sha-512
? crypto/sha/sha1-armv4-large.S
? crypto/sha/sha256-armv4.S
? crypto/sha/sha512-armv4.S
Index: crypto/objects/obj_xref.c
===================================================================
RCS file: /v/openssl/cvs/openssl/crypto/objects/obj_xref.c,v
retrieving revision 1.9
diff -u -r1.9 obj_xref.c
--- crypto/objects/obj_xref.c 5 Nov 2008 18:38:58 -0000 1.9
+++ crypto/objects/obj_xref.c 6 Oct 2011 20:30:21 -0000
@@ -110,8 +110,10 @@
#endif
if (rv == NULL)
return 0;
- *pdig_nid = rv->hash_id;
- *ppkey_nid = rv->pkey_id;
+ if (pdig_nid)
+ *pdig_nid = rv->hash_id;
+ if (ppkey_nid)
+ *ppkey_nid = rv->pkey_id;
return 1;
}
@@ -144,7 +146,8 @@
#endif
if (rv == NULL)
return 0;
- *psignid = (*rv)->sign_id;
+ if (psignid)
+ *psignid = (*rv)->sign_id;
return 1;
}
Index: crypto/x509/x509type.c
===================================================================
RCS file: /v/openssl/cvs/openssl/crypto/x509/x509type.c,v
retrieving revision 1.10
diff -u -r1.10 x509type.c
--- crypto/x509/x509type.c 26 Oct 2007 12:06:33 -0000 1.10
+++ crypto/x509/x509type.c 6 Oct 2011 20:36:04 -0000
@@ -100,20 +100,26 @@
break;
}
- i=X509_get_signature_type(x);
- switch (i)
+ i=OBJ_obj2nid(x->sig_alg->algorithm);
+ if (i && OBJ_find_sigid_algs(i, NULL, &i))
{
- case EVP_PKEY_RSA:
- ret|=EVP_PKS_RSA;
- break;
- case EVP_PKEY_DSA:
- ret|=EVP_PKS_DSA;
- break;
- case EVP_PKEY_EC:
- ret|=EVP_PKS_EC;
- break;
- default:
- break;
+
+ switch (i)
+ {
+ case NID_rsaEncryption:
+ case NID_rsa:
+ ret|=EVP_PKS_RSA;
+ break;
+ case NID_dsa:
+ case NID_dsa_2:
+ ret|=EVP_PKS_DSA;
+ break;
+ case NID_X9_62_id_ecPublicKey:
+ ret|=EVP_PKS_EC;
+ break;
+ default:
+ break;
+ }
}
if (EVP_PKEY_size(pk) <= 1024/8)/* /8 because it's 1024 bits we look
2011-10-06 20:44:02 +00:00
|
|
|
|
2015-09-02 21:01:18 +00:00
|
|
|
i = X509_get_signature_nid(x);
|
2015-01-22 03:40:55 +00:00
|
|
|
if (i && OBJ_find_sigid_algs(i, NULL, &i)) {
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
switch (i) {
|
|
|
|
case NID_rsaEncryption:
|
|
|
|
case NID_rsa:
|
|
|
|
ret |= EVP_PKS_RSA;
|
|
|
|
break;
|
|
|
|
case NID_dsa:
|
|
|
|
case NID_dsa_2:
|
|
|
|
ret |= EVP_PKS_DSA;
|
|
|
|
break;
|
|
|
|
case NID_X9_62_id_ecPublicKey:
|
|
|
|
ret |= EVP_PKS_EC;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2017-10-17 14:04:09 +00:00
|
|
|
return ret;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|