File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
2424#include <errno.h>
2525#include <assert.h>
2626#include <ipxe/list.h>
27+ #include <ipxe/base16.h>
2728#include <ipxe/asn1.h>
2829#include <ipxe/crypto.h>
2930#include <ipxe/md5.h>
@@ -120,14 +121,23 @@ FILE_LICENCE ( GPL2_OR_LATER );
120121 */
121122const char * x509_name ( struct x509_certificate * cert ) {
122123 struct asn1_cursor * common_name = & cert -> subject .common_name ;
124+ struct digest_algorithm * digest = & sha1_algorithm ;
123125 static char buf [64 ];
126+ uint8_t fingerprint [ digest -> digestsize ];
124127 size_t len ;
125128
126129 len = common_name -> len ;
127- if ( len > ( sizeof ( buf ) - 1 /* NUL */ ) )
128- len = ( sizeof ( buf ) - 1 /* NUL */ );
129- memcpy ( buf , common_name -> data , len );
130- buf [len ] = '\0' ;
130+ if ( len ) {
131+ /* Certificate has a commonName: use that */
132+ if ( len > ( sizeof ( buf ) - 1 /* NUL */ ) )
133+ len = ( sizeof ( buf ) - 1 /* NUL */ );
134+ memcpy ( buf , common_name -> data , len );
135+ buf [len ] = '\0' ;
136+ } else {
137+ /* Certificate has no commonName: use SHA-1 fingerprint */
138+ x509_fingerprint ( cert , digest , fingerprint );
139+ base16_encode ( fingerprint , sizeof ( fingerprint ), buf );
140+ }
131141 return buf ;
132142}
133143
You can’t perform that action at this time.
0 commit comments