test_suite_x509parse.function 5.26 KB
Newer Older
1 2
BEGIN_HEADER
#include <polarssl/x509.h>
3
#include <polarssl/pem.h>
4 5 6

int verify_none( void *data, x509_cert *crt, int certificate_depth, int preverify_ok )
{
Paul Bakker's avatar
Paul Bakker committed
7 8 9 10 11
    ((void) data);
    ((void) crt);
    ((void) certificate_depth);
    ((void) preverify_ok);

12 13 14 15 16
    return 1;
}

int verify_all( void *data, x509_cert *crt, int certificate_depth, int preverify_ok )
{
Paul Bakker's avatar
Paul Bakker committed
17 18 19 20 21
    ((void) data);
    ((void) crt);
    ((void) certificate_depth);
    ((void) preverify_ok);

22 23 24
    return 0;
}

25 26
END_HEADER

27 28 29 30
BEGIN_DEPENDENCIES
depends_on:POLARSSL_X509_PARSE_C:POLARSSL_BIGNUM_C
END_DEPENDENCIES

31 32 33 34 35
BEGIN_CASE
x509_cert_info:crt_file:result_str
{
    x509_cert   crt;
    char buf[2000];
36
    int res;
37 38 39 40 41

    memset( &crt, 0, sizeof( x509_cert ) );
    memset( buf, 0, 2000 );

    TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
42
    res = x509parse_cert_info( buf, 2000, "", &crt );
43 44 45 46 47 48 49 50 51 52 53 54 55

    TEST_ASSERT( res != -1 );
    TEST_ASSERT( res != -2 );

    TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
}
END_CASE

BEGIN_CASE
x509_crl_info:crl_file:result_str
{
    x509_crl   crl;
    char buf[2000];
56
    int res;
57 58 59 60 61

    memset( &crl, 0, sizeof( x509_crl ) );
    memset( buf, 0, 2000 );

    TEST_ASSERT( x509parse_crlfile( &crl, {crl_file} ) == 0 );
62
    res = x509parse_crl_info( buf, 2000, "", &crl );
63 64 65 66 67 68 69 70 71

    TEST_ASSERT( res != -1 );
    TEST_ASSERT( res != -2 );

    TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
}
END_CASE

BEGIN_CASE
72
x509_verify:crt_file:ca_file:crl_file:cn_name:result:flags:verify_callback
73 74 75 76 77
{
    x509_cert   crt;
    x509_cert   ca;
    x509_crl    crl;
    int         flags = 0;
78
    int         res;
79 80 81 82 83 84 85 86 87

    memset( &crt, 0, sizeof( x509_cert ) );
    memset( &ca, 0, sizeof( x509_cert ) );
    memset( &crl, 0, sizeof( x509_crl ) );

    TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
    TEST_ASSERT( x509parse_crtfile( &ca, {ca_file} ) == 0 );
    TEST_ASSERT( x509parse_crlfile( &crl, {crl_file} ) == 0 );

88
    res = x509parse_verify( &crt, &ca, &crl, {cn_name}, &flags, {verify_callback}, NULL );
89

90 91
    TEST_ASSERT( res == ( {result} ) );
    TEST_ASSERT( flags == ( {flags} ) );
92 93 94 95 96 97 98 99
}
END_CASE

BEGIN_CASE
x509_dn_gets:crt_file:entity:result_str
{
    x509_cert   crt;
    char buf[2000];
100
    int res;
101 102 103 104 105

    memset( &crt, 0, sizeof( x509_cert ) );
    memset( buf, 0, 2000 );

    TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
106
    res =  x509parse_dn_gets( buf, 2000, &crt.{entity} );
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

    TEST_ASSERT( res != -1 );
    TEST_ASSERT( res != -2 );

    TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
}
END_CASE

BEGIN_CASE
x509_time_expired:crt_file:entity:result
{
    x509_cert   crt;

    memset( &crt, 0, sizeof( x509_cert ) );

    TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
    TEST_ASSERT( x509parse_time_expired( &crt.{entity} ) == {result} );
}
END_CASE

BEGIN_CASE
128
x509parse_keyfile:key_file:password:result
129 130
{
    rsa_context rsa;
131
    int res;
132 133 134

    memset( &rsa, 0, sizeof( rsa_context ) );

135
    res = x509parse_keyfile( &rsa, {key_file}, {password} );
136 137 138 139 140 141 142 143 144 145

    TEST_ASSERT( res == {result} );

    if( res == 0 )
    {
        TEST_ASSERT( rsa_check_privkey( &rsa ) == 0 );
    }
}
END_CASE

146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
BEGIN_CASE
x509parse_public_keyfile:key_file:result
{
    rsa_context rsa;
    int res;

    memset( &rsa, 0, sizeof( rsa_context ) );

    res = x509parse_public_keyfile( &rsa, {key_file} );

    TEST_ASSERT( res == {result} );

    if( res == 0 )
    {
        TEST_ASSERT( rsa_check_pubkey( &rsa ) == 0 );
    }
}
END_CASE

165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
BEGIN_CASE
x509parse_crt:crt_data:result_str:result
{
    x509_cert   crt;
    unsigned char buf[2000];
    unsigned char output[2000];
    int data_len, res;

    memset( &crt, 0, sizeof( x509_cert ) );
    memset( buf, 0, 2000 );
    memset( output, 0, 2000 );

    data_len = unhexify( buf, {crt_data} );

    TEST_ASSERT( x509parse_crt( &crt, buf, data_len ) == ( {result} ) );
    if( ( {result} ) == 0 )
    {
        res = x509parse_cert_info( (char *) output, 2000, "", &crt );
        
        TEST_ASSERT( res != -1 );
        TEST_ASSERT( res != -2 );

        TEST_ASSERT( strcmp( (char *) output, {result_str} ) == 0 );
    }
}
END_CASE

192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
BEGIN_CASE
x509parse_crl:crl_data:result_str:result
{
    x509_crl   crl;
    unsigned char buf[2000];
    unsigned char output[2000];
    int data_len, res;

    memset( &crl, 0, sizeof( x509_crl ) );
    memset( buf, 0, 2000 );
    memset( output, 0, 2000 );

    data_len = unhexify( buf, {crl_data} );

    TEST_ASSERT( x509parse_crl( &crl, buf, data_len ) == ( {result} ) );
    if( ( {result} ) == 0 )
    {
        res = x509parse_crl_info( (char *) output, 2000, "", &crl );
        
        TEST_ASSERT( res != -1 );
        TEST_ASSERT( res != -2 );

        TEST_ASSERT( strcmp( (char *) output, {result_str} ) == 0 );
    }
}
END_CASE

BEGIN_CASE
x509parse_key:key_data:result_str:result
{
    rsa_context   rsa;
    unsigned char buf[2000];
    unsigned char output[2000];
    int data_len, res;

    memset( &rsa, 0, sizeof( rsa_context ) );
    memset( buf, 0, 2000 );
    memset( output, 0, 2000 );

    data_len = unhexify( buf, {key_data} );

    res = x509parse_key( &rsa, buf, data_len, NULL, 0 );

    TEST_ASSERT( x509parse_key( &rsa, buf, data_len, NULL, 0 ) == ( {result} ) );
    if( ( {result} ) == 0 )
    {
        TEST_ASSERT( 1 );
    }
}
END_CASE

243 244 245 246 247 248
BEGIN_CASE
x509_selftest:
{
    TEST_ASSERT( x509_self_test( 0 ) == 0 );
}
END_CASE