コード例 #1
0
ファイル: echo.c プロジェクト: MI-LA01/kt_wso2-php5.3
rampart_saml_token_t * AXIS2_CALL
create_saml_token(const axutil_env_t *env)
{
    oxs_sign_ctx_t *sign_ctx = NULL;
	oxs_x509_cert_t *cert = NULL;
	openssl_pkey_t *prv_key = NULL;
	rampart_saml_token_t *saml = NULL;

	axutil_date_time_t *time = NULL;
	saml_assertion_t *assertion = NULL;
	axiom_node_t *node = NULL;
    axis2_char_t *prv_key_file = NULL;
    axis2_char_t *certificate_file = NULL;
    /* 
     * Create a rampart_saml_token_t to give to the Rampart/C 
     * Here the token type is protection token.
     */    
	saml = rampart_saml_token_create(env, NULL, RAMPART_ST_CONFIR_TYPE_HOLDER_OF_KEY);
	time = axutil_date_time_create(env);
	assertion = saml_assertion_create(env);
	if (assertion)	
	{
		saml_assertion_set_minor_version(assertion, env, 1);		
		saml_assertion_set_issue_instant(assertion, env, time);
		saml_assertion_set_issuer(assertion, env, "http://ws.apache.org/rampart/c");	
		saml_assertion_add_condition(assertion, env, create_condition(env));
		saml_assertion_set_not_before(assertion, env, axutil_date_time_create(env));
		saml_assertion_add_statement(assertion, env, create_auth_statement(env, saml));
	}
    /* Load the private key from file*/
    prv_key_file = axutil_stracat(env, axis2c_home, PRIVATE_KEY_FILE);  
    certificate_file = axutil_stracat(env, axis2c_home, CERTIFICATE_FILE);
    prv_key = oxs_key_mgr_load_private_key_from_pem_file(env, prv_key_file, PRIVATE_KEY_PASSWORD);
    cert = oxs_key_mgr_load_x509_cert_from_pem_file(env, certificate_file);

	sign_ctx = oxs_sign_ctx_create(env);
	saml_util_set_sig_ctx_defaults(sign_ctx, env, "AssertionID");
	oxs_sign_ctx_set_private_key(sign_ctx, env, prv_key);
    oxs_sign_ctx_set_certificate(sign_ctx, env, cert);
    saml_assertion_set_signature(assertion, env, sign_ctx);

	node = saml_assertion_to_om(assertion, NULL, env);	 
	rampart_saml_token_set_assertion(saml, env, node);
    rampart_saml_token_set_token_type(saml, env, RAMPART_ST_TYPE_PROTECTION_TOKEN);
	saml_assertion_free(assertion, env);
	return saml;
}
コード例 #2
0
ファイル: test.c プロジェクト: alexis-gruet/kt_rampart
int main(int argc, char *argv[])
{
    axutil_env_t *env = NULL;
    axis2_char_t *filename = NULL;
    axis2_char_t *certfile = NULL;
    axis2_char_t *prvkeyfile = NULL;
    axis2_char_t *operation = NULL;
    openssl_pkey_t *prvkey = NULL;
    oxs_x509_cert_t *cert = NULL;


    if (argc > 2){
        filename = argv[1];
        operation = argv[2];
        certfile = argv[3];
        prvkeyfile = argv[4];
    }else{
        printf("Usage ./test inputfile operation[S/V] certificate prvkey \n");
        return -1;
    }
    
    env = axutil_env_create_all("./oxs.log", AXIS2_LOG_LEVEL_TRACE);
    printf("--Testing started--------------------------------------------\n");
    
    /*Load private key*/
    prvkey = oxs_key_mgr_load_private_key_from_pem_file(env, prvkeyfile, "");
    if(!prvkey){
            printf("Cannot load private key");
    }

    /*Load certificate*/
    cert = oxs_key_mgr_load_x509_cert_from_pem_file(env, certfile);
    if(!cert){
         printf("Cannot load certificate");
    }
    
    if(0 == axutil_strcmp(operation, "S")){
        sign(env, filename, prvkey, cert);
    }else{
        verify(env, filename, prvkey, cert);
    }

    printf("\nDONE\n");
    return 0;
}