futility/cmd_vbutil_key.c
/* Unpack a .vbpubk or .vbprivk */
Unpack a .vbpubk or .vbprivk
Unpack a . vbpubk or . vbprivk
static int do_unpack(const char *infile, const char *outfile)
{
	struct vb2_packed_key *pubkey;
	if (!infile) {
		fprintf(stderr, "Need file to unpack\n");
		return 1;
	}
	pubkey = vb2_read_packed_key(infile);
	if (pubkey) {
		printf("Public Key file:   %s\n", infile);
		printf("Algorithm:         %u %s\n", pubkey->algorithm,
		       vb2_get_crypto_algorithm_name(pubkey->algorithm));
		printf("Key Version:       %u\n", pubkey->key_version);
		printf("Key sha1sum:       %s\n",
		       packed_key_sha1_string(pubkey));
		if (outfile &&
		    VB2_SUCCESS != vb2_write_packed_key(outfile, pubkey)) {
			fprintf(stderr, "butil_key: Error writing key copy\n");
			free(pubkey);
			return 1;
		}
		free(pubkey);
		return 0;
	}
	struct vb2_private_key *privkey = vb2_read_private_key(infile);
	if (privkey) {
		printf("Private Key file:  %s\n", infile);
		enum vb2_crypto_algorithm alg =
			vb2_get_crypto_algorithm(privkey->hash_alg,
						 privkey->sig_alg);
		printf("Algorithm:         %u %s\n", alg,
		       vb2_get_crypto_algorithm_name(alg));
		if (outfile &&
		    VB2_SUCCESS != vb2_write_private_key(outfile, privkey)) {
			fprintf(stderr,"vbutil_key: Error writing key copy\n");
			free(privkey);
			return 1;
		}
		free(privkey);
		return 0;
	}
	FATAL("Unable to parse either .vbpubk or vbprivk from %s\n", infile);
	return 1;
}
static int do_unpack ( const char * infile , const char * outfile ) { struct vb2_packed_key * pubkey ; if ( ! infile ) { fprintf ( stderr , " \n " ) ; return 1 ; } pubkey = vb2_read_packed_key ( infile ) ; if ( pubkey ) { printf ( " \n " , infile ) ; printf ( " \n " , pubkey -> algorithm , vb2_get_crypto_algorithm_name ( pubkey -> algorithm ) ) ; printf ( " \n " , pubkey -> key_version ) ; printf ( " \n " , packed_key_sha1_string ( pubkey ) ) ; if ( outfile && VB2_SUCCESS != vb2_write_packed_key ( outfile , pubkey ) ) { fprintf ( stderr , " \n " ) ; free ( pubkey ) ; return 1 ; } free ( pubkey ) ; return 0 ; } struct vb2_private_key * privkey = vb2_read_private_key ( infile ) ; if ( privkey ) { printf ( " \n " , infile ) ; enum vb2_crypto_algorithm alg = vb2_get_crypto_algorithm ( privkey -> hash_alg , privkey -> sig_alg ) ; printf ( " \n " , alg , vb2_get_crypto_algorithm_name ( alg ) ) ; if ( outfile && VB2_SUCCESS != vb2_write_private_key ( outfile , privkey ) ) { fprintf ( stderr , " \n " ) ; free ( privkey ) ; return 1 ; } free ( privkey ) ; return 0 ; } FATAL ( " \n " , infile ) ; return 1 ; }
Unpack a .vbpubk or .vbprivk
Unpack a . vbpubk or . vbprivk