Skip to content
This repository was archived by the owner on Oct 29, 2021. It is now read-only.

Commit b91872c

Browse files
committed
Fix getting SSL public key algorithm
1 parent a0ce85d commit b91872c

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/tls_openssl.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,17 @@ static struct _tlscert_t *_x509_to_tlscert(xmpp_ctx_t *ctx, X509 *cert)
169169

170170
tlscert->keyalg = NULL;
171171
#if OPENSSL_VERSION_NUMBER < 0x10100000L
172-
int alg_nid = OBJ_obj2nid(cert->cert_info->key->algor->algorithm);
172+
int alg_nid = OBJ_obj2nid(cert->cert_info->key->algor->algorithm);
173173
#else
174-
X509_PUBKEY *pubkey = X509_get_X509_PUBKEY(cert);
175-
ASN1_OBJECT *ppkalg;
176-
// FIXME: handle 0 on error.
177-
X509_PUBKEY_get0_param(&ppkalg, NULL, NULL, NULL, NULL);
178-
int alg_nid = OBJ_obj2nid(ppkalg);
174+
X509_PUBKEY *pubkey = X509_get_X509_PUBKEY(cert);
175+
ASN1_OBJECT *ppkalg = NULL;
176+
int alg_nid = NID_undef;
177+
res = X509_PUBKEY_get0_param(&ppkalg, NULL, NULL, NULL, pubkey);
178+
if (res) {
179+
alg_nid = OBJ_obj2nid(ppkalg);
180+
}
179181
#endif
180-
if (alg_nid != NID_undef) {
182+
if (alg_nid != NID_undef) {
181183
const char* keyalg = OBJ_nid2ln(alg_nid);
182184
if (keyalg) {
183185
tlscert->keyalg = xmpp_strdup(ctx, keyalg);
@@ -186,13 +188,13 @@ static struct _tlscert_t *_x509_to_tlscert(xmpp_ctx_t *ctx, X509 *cert)
186188

187189
tlscert->sigalg = NULL;
188190
#if OPENSSL_VERSION_NUMBER < 0x10100000L
189-
alg_nid = OBJ_obj2nid(cert->sig_alg->algorithm);
191+
alg_nid = OBJ_obj2nid(cert->sig_alg->algorithm);
190192
#else
191-
const X509_ALGOR *palg;
192-
X509_get0_signature(NULL, &palg, cert);
193-
alg_nid = OBJ_obj2nid(palg->algorithm);
193+
const X509_ALGOR *palg;
194+
X509_get0_signature(NULL, &palg, cert);
195+
alg_nid = OBJ_obj2nid(palg->algorithm);
194196
#endif
195-
if (alg_nid != NID_undef) {
197+
if (alg_nid != NID_undef) {
196198
const char* sigalg = OBJ_nid2ln(alg_nid);
197199
if (sigalg) {
198200
tlscert->sigalg = xmpp_strdup(ctx, sigalg);

0 commit comments

Comments
 (0)