예제 #1
0
파일: test3.c 프로젝트: a157634/libpki
int main (int argc, char *argv[] ) {

	printf("\n\nlibpki Test - Massimiliano Pala <*****@*****.**>\n");
	printf("(c) 2006 by Massimiliano Pala and OpenCA Project\n");
	printf("OpenCA Licensed Software\n\n");

	printf("TOKEN Generation testsuite.\n\n");

	if(( PKI_log_init (PKI_LOG_TYPE_SYSLOG, PKI_LOG_NOTICE, NULL,
			PKI_LOG_FLAGS_ENABLE_DEBUG, NULL )) == PKI_ERR ) {
		exit(1);
	}

	gen_X509_tk(PKI_SCHEME_RSA, 1024, "results/cert_rsa_1024.pem");
	gen_X509_tk(PKI_SCHEME_RSA, 2048, "results/cert_rsa_2048.pem");
	gen_X509_tk(PKI_SCHEME_RSA, 4096, "results/cert_rsa_4096.pem");
	gen_X509_tk(PKI_SCHEME_DSA, 2048,"results/cert_dsa_2048.pem");
	gen_X509_tk(PKI_SCHEME_ECDSA, 256, "results/cert_ecdsa_256.pem");

	PKI_log_end();

	printf("Done.\n\n");

	return (0);
}
예제 #2
0
파일: test6.c 프로젝트: openca/libpki
int main (int argc, char *argv[] ) {

	PKI_TOKEN *tk = NULL;
	PKI_X509_PROFILE *prof =  NULL;
	// PKI_OID *oid = NULL;

	PKI_X509_CRL *crl = NULL;
	PKI_X509_CRL_ENTRY *entry = NULL;
	PKI_X509_CRL_ENTRY_STACK *sk = NULL;

	printf("\n\nlibpki Test - Massimiliano Pala <*****@*****.**>\n");
	printf("(c) 2006 by Massimiliano Pala and OpenCA Project\n");
	printf("OpenCA Licensed Software\n\n");

	if(( PKI_log_init (PKI_LOG_TYPE_STDERR, PKI_LOG_NOTICE, NULL,
			PKI_LOG_FLAGS_ENABLE_DEBUG, NULL )) == PKI_ERR ) {
		exit(1);
	}

	if((tk = PKI_TOKEN_new_null()) == NULL ) {
		printf("ERROR, can not allocate token!\n\n");
		exit(1);
	}

	if(( PKI_TOKEN_init( tk, "etc" , "Default" )) == PKI_ERR) {
		printf("ERROR, can not configure token!\n\n");
		exit(1);
	}

	if((PKI_TOKEN_set_algor ( tk, PKI_ALGOR_RSA_SHA256 )) == PKI_ERR ) {
                printf("ERROR, can not set the RSA crypto scheme!\n");
                return (0);
        }

        if((PKI_TOKEN_new_keypair ( tk, 1024, NULL )) == PKI_ERR) {
                printf("ERROR, can not generate new keypair!\n");
                return (0);
        }

	printf("* Self Signing certificate .... ");
        if((PKI_TOKEN_self_sign( tk, NULL, "23429", 24*3600, "User" )) == PKI_ERR ) {
                printf("ERROR, can not self sign certificate!\n");
                return(0);
        }

	printf("Generating a new CRL ENTRY ... ");
	if((entry = PKI_X509_CRL_ENTRY_new_serial ( "12345678", 
			CRL_REASON_KEY_COMPROMISE, NULL, NULL )) 
								== NULL ) {
		printf("ERROR!\n");
		exit(1);
	}
	printf("Ok\n");

	sk = PKI_STACK_X509_CRL_ENTRY_new();
	PKI_STACK_X509_CRL_ENTRY_push( sk, entry );

	printf("Generating new CRL ... ");
	if((crl = PKI_TOKEN_issue_crl (tk, "3", 
				PKI_VALIDITY_ONE_WEEK, sk, "crl")) == NULL ) {
		printf("ERROR, can not generate new CRL!\n");
		exit(1);
	}
	printf("Ok\n");

	if( tk ) PKI_TOKEN_free ( tk );
	if( prof ) PKI_X509_PROFILE_free ( prof );
	if( crl )  PKI_X509_CRL_free ( crl );

	PKI_log_end();

	printf("\n\n[ Test Ended Succesfully ]\n\n");

	return (0);
}