Exemplo n.º 1
0
void Test_Time()
{
    LCD_Clear();
    lcd_printf("Testing SSL Time functions...\n");
	SYSTEMTIME systime;

	INT64 getlocaltime = Time_GetLocalTime();
	TINYCLR_SSL_PRINTF("Time_GetLocalTime(): %d\n", getlocaltime);
	Time_ToSystemTime(getlocaltime,&systime);
	INT64 fromsystemtime = Time_FromSystemTime(&systime);
	TINYCLR_SSL_PRINTF("Time_FromSystemTime: %d\n", fromsystemtime);

	time_t time = TINYCLR_SSL_TIME(NULL);
	TINYCLR_SSL_PRINTF("TINYCLR_SSL_TIME in ms: %d\n", (INT64)time);
	struct tm *local =	TINYCLR_SSL_LOCALTIME(&time);
	TINYCLR_SSL_PRINTF("Local Time: %s %2d %02d:%02d:%02d %d\n",
		mon[local->tm_mon-1],
		local->tm_mday,
		local->tm_hour,
		local->tm_min,
		local->tm_sec,
		local->tm_year);
	
	struct tm *gmtime =	TINYCLR_SSL_GMTIME(&time);
	TINYCLR_SSL_PRINTF("GM Time: %s %2d %02d:%02d:%02d %d\n",
		mon[gmtime->tm_mon],
		gmtime->tm_mday,
		gmtime->tm_hour,
		gmtime->tm_min,
		gmtime->tm_sec,
		gmtime->tm_year);
}
Exemplo n.º 2
0
static void print_conf(CONF_VALUE *cv)
	{
	int i;
	CONF_VALUE *v;
	char *section;
	char *name;
	char *value;
	STACK *s;

	/* If it is a single entry, return */

	if (cv->name != NULL) return;

	TINYCLR_SSL_PRINTF("[ %s ]\n",cv->section);
	s=(STACK *)cv->value;

	for (i=0; i<sk_num(s); i++)
		{
		v=(CONF_VALUE *)sk_value(s,i);
		section=(v->section == NULL)?"None":v->section;
		name=(v->name == NULL)?"None":v->name;
		value=(v->value == NULL)?"None":v->value;
		TINYCLR_SSL_PRINTF("%s=%s\n",name,value);
		}
	TINYCLR_SSL_PRINTF("\n");
	}
Exemplo n.º 3
0
main()
	{
	LHASH *conf;
	long eline;
	char *s,*s2;

#ifdef USE_WIN32
	CONF_set_default_method(CONF_WIN32);
#endif
	conf=CONF_load(NULL,"ssleay.cnf",&eline);
	if (conf == NULL)
		{
		ERR_load_crypto_strings();
		TINYCLR_SSL_PRINTF("unable to load configuration, line %ld\n",eline);
		ERR_print_errors_fp(OPENSSL_TYPE__FILE_STDERR);
		TINYCLR_SSL_EXIT(1);
		}
	lh_stats(conf,OPENSSL_TYPE__FILE_STDOUT);
	lh_node_stats(conf,OPENSSL_TYPE__FILE_STDOUT);
	lh_node_usage_stats(conf,OPENSSL_TYPE__FILE_STDOUT);

	s=CONF_get_string(conf,NULL,"init2");
	TINYCLR_SSL_PRINTF("init2=%s\n",(s == NULL)?"NULL":s);

	s=CONF_get_string(conf,NULL,"cipher1");
	TINYCLR_SSL_PRINTF("cipher1=%s\n",(s == NULL)?"NULL":s);

	s=CONF_get_string(conf,"s_client","cipher1");
	TINYCLR_SSL_PRINTF("s_client:cipher1=%s\n",(s == NULL)?"NULL":s);

	TINYCLR_SSL_PRINTF("---------------------------- DUMP ------------------------\n");
	CONF_dump_fp(conf, OPENSSL_TYPE__FILE_STDOUT);

	TINYCLR_SSL_EXIT(0);
	}
int main(int argc, char *argv[])
	{
	int i,err=0;
	char **P,**R;
	char *p;
	unsigned char md[RIPEMD160_DIGEST_LENGTH];

	P=test;
	R=ret;
	i=1;
	while (*P != NULL)
		{
#ifdef CHARSET_EBCDIC
		ebcdic2ascii((char *)*P, (char *)*P, TINYCLR_SSL_STRLEN((char *)*P));
#endif
		EVP_Digest(&(P[0][0]),TINYCLR_SSL_STRLEN((char *)*P),md,NULL,EVP_ripemd160(), NULL);
		p=pt(md);
		if (TINYCLR_SSL_STRCMP(p,(char *)*R) != 0)
			{
			TINYCLR_SSL_PRINTF("error calculating RIPEMD160 on '%s'\n",*P);
			TINYCLR_SSL_PRINTF("got %s instead of %s\n",p,*R);
			err++;
			}
		else
			TINYCLR_SSL_PRINTF("test %d ok\n",i);
		i++;
		R++;
		P++;
		}
	EXIT(err);
	return(0);
	}
Exemplo n.º 5
0
int main(int argc, char *argv[])
{
    int i,err=0;
    char **P,**R;
    char *p;
    unsigned char md[MD4_DIGEST_LENGTH];

    P=test;
    R=ret;
    i=1;
    while (*P != NULL)
    {
        EVP_Digest(&(P[0][0]),TINYCLR_SSL_STRLEN((char *)*P),md,NULL,EVP_md4(), NULL);
        p=pt(md);
        if (TINYCLR_SSL_STRCMP(p,(char *)*R) != 0)
        {
            TINYCLR_SSL_PRINTF("error calculating MD4 on '%s'\n",*P);
            TINYCLR_SSL_PRINTF("got %s instead of %s\n",p,*R);
            err++;
        }
        else
            TINYCLR_SSL_PRINTF("test %d ok\n",i);
        i++;
        R++;
        P++;
    }
    EXIT(err);
    return(0);
}
Exemplo n.º 6
0
main()
	{
	int n1, n2, n3;

	int i, rv;
#ifdef OBJ_XREF_TEST2
	for (i = 0; i <	sizeof(sigoid_srt) / sizeof(nid_triple); i++)
		{
		OBJ_add_sigid(sigoid_srt[i][0], sigoid_srt[i][1],
				sigoid_srt[i][2]);
		}
#endif

	for (i = 0; i <	sizeof(sigoid_srt) / sizeof(nid_triple); i++)
		{
		n1 = sigoid_srt[i][0];
		rv = OBJ_find_sigid_algs(n1, &n2, &n3);
		TINYCLR_SSL_PRINTF("Forward: %d, %s %s %s\n", rv,
			OBJ_nid2ln(n1), OBJ_nid2ln(n2), OBJ_nid2ln(n3));
		n1=0;
		rv = OBJ_find_sigid_by_algs(&n1, n2, n3);
		TINYCLR_SSL_PRINTF("Reverse: %d, %s %s %s\n", rv,
			OBJ_nid2ln(n1), OBJ_nid2ln(n2), OBJ_nid2ln(n3));
		}
	}
Exemplo n.º 7
0
static int cfb64_test(unsigned char *cfb_cipher)
	{
	des_key_schedule ks;
	int err=0,i,n;

	DES_set_key_checked(&cfb_key,&ks);
	TINYCLR_SSL_MEMCPY(cfb_tmp,cfb_iv,sizeof(cfb_iv));
	n=0;
	des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT);
	des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),sizeof(plain)-12,ks,
			  &cfb_tmp,&n,DES_ENCRYPT);
	if (TINYCLR_SSL_MEMCMP(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
		{
		err=1;
		TINYCLR_SSL_PRINTF("cfb_encrypt encrypt error\n");
		for (i=0; i<24; i+=8)
			TINYCLR_SSL_PRINTF("%s\n",pt(&(cfb_buf1[i])));
		}
	TINYCLR_SSL_MEMCPY(cfb_tmp,cfb_iv,sizeof(cfb_iv));
	n=0;
	des_cfb64_encrypt(cfb_buf1,cfb_buf2,17,ks,&cfb_tmp,&n,DES_DECRYPT);
	des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
			  sizeof(plain)-17,ks,&cfb_tmp,&n,DES_DECRYPT);
	if (TINYCLR_SSL_MEMCMP(plain,cfb_buf2,sizeof(plain)) != 0)
		{
		err=1;
		TINYCLR_SSL_PRINTF("cfb_encrypt decrypt error\n");
		for (i=0; i<24; i+=8)
			TINYCLR_SSL_PRINTF("%s\n",pt(&(cfb_buf2[i])));
		}
	return(err);
	}
Exemplo n.º 8
0
static int cfb_test(int bits, unsigned char *cfb_cipher)
	{
	des_key_schedule ks;
	int i,err=0;

	DES_set_key_checked(&cfb_key,&ks);
	TINYCLR_SSL_MEMCPY(cfb_tmp,cfb_iv,sizeof(cfb_iv));
	des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp,
			DES_ENCRYPT);
	if (TINYCLR_SSL_MEMCMP(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
		{
		err=1;
		TINYCLR_SSL_PRINTF("cfb_encrypt encrypt error\n");
		for (i=0; i<24; i+=8)
			TINYCLR_SSL_PRINTF("%s\n",pt(&(cfb_buf1[i])));
		}
	TINYCLR_SSL_MEMCPY(cfb_tmp,cfb_iv,sizeof(cfb_iv));
	des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,sizeof(plain),ks,&cfb_tmp,
			DES_DECRYPT);
	if (TINYCLR_SSL_MEMCMP(plain,cfb_buf2,sizeof(plain)) != 0)
		{
		err=1;
		TINYCLR_SSL_PRINTF("cfb_encrypt decrypt error\n");
		for (i=0; i<24; i+=8)
			TINYCLR_SSL_PRINTF("%s\n",pt(&(cfb_buf1[i])));
		}
	return(err);
	}
main()
{
	ASN1_STRING_TABLE *tmp;
	int i, last_nid = -1;

	for (tmp = tbl_standard, i = 0;
		i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++)
		{
			if (tmp->nid < last_nid)
				{
				last_nid = 0;
				break;
				}
			last_nid = tmp->nid;
		}

	if (last_nid != 0)
		{
		TINYCLR_SSL_PRINTF("Table order OK\n");
		TINYCLR_SSL_EXIT(0);
		}

	for (tmp = tbl_standard, i = 0;
		i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++)
			TINYCLR_SSL_PRINTF("Index %d, NID %d, Name=%s\n", i, tmp->nid,
							OBJ_nid2ln(tmp->nid));

}
Exemplo n.º 10
0
void pt(unsigned char *md)
	{
	int i;

	for (i=0; i<SHA_DIGEST_LENGTH; i++)
		TINYCLR_SSL_PRINTF("%02x",md[i]);
	TINYCLR_SSL_PRINTF("\n");
	}
main()
	{
	unsigned char md[MDC2_DIGEST_LENGTH];
	int i;
	MDC2_CTX c;
	static char *text="Now is the time for all ";

	MDC2_Init(&c);
	MDC2_Update(&c,text,TINYCLR_SSL_STRLEN(text));
	MDC2_Final(&(md[0]),&c);

	for (i=0; i<MDC2_DIGEST_LENGTH; i++)
		TINYCLR_SSL_PRINTF("%02X",md[i]);
	TINYCLR_SSL_PRINTF("\n");
	}
Exemplo n.º 12
0
static int verify_command(char *data, char *digest, char *queryfile,
			  char *in, int token_in,
			  char *ca_path, char *ca_file, char *untrusted)
	{
	BIO *in_bio = NULL;
	PKCS7 *token = NULL;
	TS_RESP *response = NULL;
	TS_VERIFY_CTX *verify_ctx = NULL;
	int ret = 0;

	/* Decode the token (PKCS7) or response (TS_RESP) files. */
	if (!(in_bio = BIO_new_file(in, "rb"))) goto end;
	if (token_in)
		{
		if (!(token = d2i_PKCS7_bio(in_bio, NULL))) goto end;
		}
	else
		{
		if (!(response = d2i_TS_RESP_bio(in_bio, NULL))) goto end;
		}

	if (!(verify_ctx = create_verify_ctx(data, digest, queryfile, 
					     ca_path, ca_file, untrusted)))
		goto end;

	/* Checking the token or response against the request. */
	ret = token_in ?
		TS_RESP_verify_token(verify_ctx, token) :
		TS_RESP_verify_response(verify_ctx, response);

 end:
	TINYCLR_SSL_PRINTF("Verification: ");
	if (ret)
		TINYCLR_SSL_PRINTF("OK\n");
	else
		{
		TINYCLR_SSL_PRINTF("FAILED\n");
		/* Print errors, if there are any. */
		ERR_print_errors(bio_err);
		}
	
	/* Clean up. */
	BIO_free_all(in_bio);
	PKCS7_free(token);
	TS_RESP_free(response);
	TS_VERIFY_CTX_free(verify_ctx);
	return ret;
	}
STACK_OF(X509) *TS_CONF_load_certs(const char *file)
	{
	BIO *certs = NULL;
	STACK_OF(X509) *othercerts = NULL;
	STACK_OF(X509_INFO) *allcerts = NULL;
	int i;

	if (!(certs = BIO_new_file(file, "r"))) goto end;

	if (!(othercerts = sk_X509_new_null())) goto end;
	allcerts = PEM_X509_INFO_read_bio(certs, NULL, NULL, NULL);
	for(i = 0; i < sk_X509_INFO_num(allcerts); i++)
		{
		X509_INFO *xi = sk_X509_INFO_value(allcerts, i);
		if (xi->x509)
			{
			sk_X509_push(othercerts, xi->x509);
			xi->x509 = NULL;
			}
		}
end:
	if (othercerts == NULL)
		TINYCLR_SSL_PRINTF("unable to load certificates: %s\n", file);
	sk_X509_INFO_pop_free(allcerts, X509_INFO_free);
	BIO_free(certs);
	return othercerts;
	}
Exemplo n.º 14
0
int main(int argc, char **argv)
	{
	int i,err=0;
	TINYCLR_SSL_FILE *IN;

	if (argc == 1)
		{
		do_fp(OPENSSL_TYPE__FILE_STDIN);
		}
	else
		{
		for (i=1; i<argc; i++)
			{
			IN=TINYCLR_SSL_FOPEN(argv[i],"r");
			if (IN == NULL)
				{
				TINYCLR_SSL_PERROR(argv[i]);
				err++;
				continue;
				}
			TINYCLR_SSL_PRINTF("SHA(%s)= ",argv[i]);
			do_fp(IN);
			TINYCLR_SSL_FCLOSE(IN);
			}
		}
	TINYCLR_SSL_EXIT(err);
	}
Exemplo n.º 15
0
static void display_engine_list(void)
	{
	ENGINE *h;
	int loop;

	h = ENGINE_get_first();
	loop = 0;
	TINYCLR_SSL_PRINTF("listing available engine types\n");
	while(h)
		{
		TINYCLR_SSL_PRINTF("engine %i, id = \"%s\", name = \"%s\"\n",
			loop++, ENGINE_get_id(h), ENGINE_get_name(h));
		h = ENGINE_get_next(h);
		}
	TINYCLR_SSL_PRINTF("end of list\n");
	/* ENGINE_get_first() increases the struct_ref counter, so we 
           must call ENGINE_free() to decrease it again */
	ENGINE_free(h);
	}
void OPENSSL_showfatal (const char *fmta,...)
{ va_list ap;

    va_start (ap,fmta);
#ifndef OPENSSL_SYS_WINDOWS
	TINYCLR_SSL_PRINTF(fmta,ap);
#else
    vfprintf (OPENSSL_TYPE__FILE_STDERR,fmta,ap);
#endif
    va_end (ap);
}
Exemplo n.º 17
0
int cb(int p, int n)
	{
	char c='*';

	if (p == 0) c='.';
	if (p == 1) c='+';
	if (p == 2) c='*';
	if (p == 3) c='\n';
	TINYCLR_SSL_PRINTF("%c",c);
	TINYCLR_SSL_FFLUSH(OPENSSL_TYPE__FILE_STDOUT);
	}
X509 *TS_CONF_load_cert(const char *file)
	{
	BIO *cert = NULL;
	X509 *x = NULL;

	if ((cert = BIO_new_file(file, "r")) == NULL) goto end;
	x = PEM_read_bio_X509_AUX(cert, NULL, NULL, NULL);
end:
	if (x == NULL)
		TINYCLR_SSL_PRINTF("unable to load certificate: %s\n", file);
	BIO_free(cert);
	return x;
	}
EVP_PKEY *TS_CONF_load_key(const char *file, const char *pass)
	{
	BIO *key = NULL;
	EVP_PKEY *pkey = NULL;

	if (!(key = BIO_new_file(file, "r"))) goto end;
	pkey = PEM_read_bio_PrivateKey(key, NULL, NULL, (char *) pass);
 end:
	if (pkey == NULL)
		TINYCLR_SSL_PRINTF("unable to load private key: %s\n", file);
	BIO_free(key);
	return pkey;
	}
Exemplo n.º 20
0
int ssl_test_bf(int argc, char *argv[])
	{
	int ret;

	if (argc > 1)
		ret=print_test_data();
	else
		ret=test();

#ifdef OPENSSL_SYS_NETWARE
    if (ret) TINYCLR_SSL_PRINTF("ERROR: %d\n", ret);
#endif
	return(ret);
	}
Exemplo n.º 21
0
int tls1_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,
	     int len)
	{
	unsigned char buff[SSL_MAX_MASTER_KEY_LENGTH];
	const void *co = NULL, *so = NULL;
	int col = 0, sol = 0;

#ifdef KSSL_DEBUG
	TINYCLR_SSL_PRINTF ("tls1_generate_master_secret(%p,%p, %p, %d)\n", s,out, p,len);
#endif	/* KSSL_DEBUG */

#ifdef TLSEXT_TYPE_opaque_prf_input
	if (s->s3->client_opaque_prf_input != NULL && s->s3->server_opaque_prf_input != NULL &&
	    s->s3->client_opaque_prf_input_len > 0 &&
	    s->s3->client_opaque_prf_input_len == s->s3->server_opaque_prf_input_len)
		{
		co = s->s3->client_opaque_prf_input;
		col = s->s3->server_opaque_prf_input_len;
		so = s->s3->server_opaque_prf_input;
		sol = s->s3->client_opaque_prf_input_len; /* must be same as col (see draft-rescorla-tls-opaque-prf-input-00.txt, section 3.1) */
		}
#endif

	tls1_PRF(s->s3->tmp.new_cipher->algorithm2,
		TLS_MD_MASTER_SECRET_CONST,TLS_MD_MASTER_SECRET_CONST_SIZE,
		s->s3->client_random,SSL3_RANDOM_SIZE,
		co, col,
		s->s3->server_random,SSL3_RANDOM_SIZE,
		so, sol,
		p,len,
		s->session->master_key,buff,sizeof buff);

#ifdef KSSL_DEBUG
	TINYCLR_SSL_PRINTF ("tls1_generate_master_secret() complete\n");
#endif	/* KSSL_DEBUG */
	return(SSL3_MASTER_SECRET_SIZE);
	}
Exemplo n.º 22
0
static int cfb64_test(unsigned char *cfb_cipher)
        {
        IDEA_KEY_SCHEDULE eks,dks;
        int err=0,i,n;

        idea_set_encrypt_key(cfb_key,&eks);
        idea_set_decrypt_key(&eks,&dks);
        TINYCLR_SSL_MEMCPY(cfb_tmp,cfb_iv,8);
        n=0;
        idea_cfb64_encrypt(plain,cfb_buf1,(long)12,&eks,
                cfb_tmp,&n,IDEA_ENCRYPT);
        idea_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
                (long)CFB_TEST_SIZE-12,&eks,
                cfb_tmp,&n,IDEA_ENCRYPT);
        if (TINYCLR_SSL_MEMCMP(cfb_cipher,cfb_buf1,CFB_TEST_SIZE) != 0)
                {
                err=1;
                TINYCLR_SSL_PRINTF("idea_cfb64_encrypt encrypt error\n");
                for (i=0; i<CFB_TEST_SIZE; i+=8)
                        TINYCLR_SSL_PRINTF("%s\n",pt(&(cfb_buf1[i])));
                }
        TINYCLR_SSL_MEMCPY(cfb_tmp,cfb_iv,8);
        n=0;
        idea_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,&eks,
                cfb_tmp,&n,IDEA_DECRYPT);
        idea_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
                (long)CFB_TEST_SIZE-17,&dks,
                cfb_tmp,&n,IDEA_DECRYPT);
        if (TINYCLR_SSL_MEMCMP(plain,cfb_buf2,CFB_TEST_SIZE) != 0)
                {
                err=1;
                TINYCLR_SSL_PRINTF("idea_cfb_encrypt decrypt error\n");
                for (i=0; i<24; i+=8)
                        TINYCLR_SSL_PRINTF("%s\n",pt(&(cfb_buf2[i])));
                }
        return(err);
        }
Exemplo n.º 23
0
void
pqueue_print(pqueue_s *pq)
	{
	pitem *item = pq->items;

	while(item != NULL)
		{
		TINYCLR_SSL_PRINTF("item\t%02x%02x%02x%02x%02x%02x%02x%02x\n",
			item->priority[0],item->priority[1],
			item->priority[2],item->priority[3],
			item->priority[4],item->priority[5],
			item->priority[6],item->priority[7]);
		item = item->next;
		}
	}
Exemplo n.º 24
0
static int tls1_generate_key_block(SSL *s, unsigned char *km,
	     unsigned char *tmp, int num)
	{
	int ret;
	ret = tls1_PRF(s->s3->tmp.new_cipher->algorithm2,
		 TLS_MD_KEY_EXPANSION_CONST,TLS_MD_KEY_EXPANSION_CONST_SIZE,
		 s->s3->server_random,SSL3_RANDOM_SIZE,
		 s->s3->client_random,SSL3_RANDOM_SIZE,
		 NULL,0,NULL,0,
		 s->session->master_key,s->session->master_key_length,
		 km,tmp,num);
#ifdef KSSL_DEBUG
	TINYCLR_SSL_PRINTF("tls1_generate_key_block() ==> %d byte master_key =\n\t",
                s->session->master_key_length);
	{
        int i;
        for (i=0; i < s->session->master_key_length; i++)
                {
                TINYCLR_SSL_PRINTF("%02X", s->session->master_key[i]);
                }
        TINYCLR_SSL_PRINTF("\n");  }
#endif    /* KSSL_DEBUG */
	return ret;
	}
Exemplo n.º 25
0
char* tinyclr_fgets(char * str, int num, OPENSSL_TYPE__FILE * stream) 
{
    int count = num;
	int cursor = 0;
    char* ptr = (char*)&stream->buffer[stream->read];
    while(*ptr != '\n' && *ptr != '\0' && count > 1 ) 
    {
        count--; ptr++; cursor++;
    };

    TINYCLR_SSL_MEMCPY(str,	&stream->buffer[stream->read], num-count+1);
	str[num-count+1] = '\0';
    stream->read += cursor+1;
	TINYCLR_SSL_PRINTF(str);
	return str;
}
Exemplo n.º 26
0
static EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id,
	UI_METHOD *ui_method, void *callback_data)
	{
	BIO *in;
	EVP_PKEY *key;
#ifndef OPENSSL_SYS_WINDOWS
	TINYCLR_SSL_PRINTF("(TEST_ENG_OPENSSL_PKEY)Loading Private key %s\n", key_id);
#else
	TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR, "(TEST_ENG_OPENSSL_PKEY)Loading Private key %s\n", key_id);
#endif
	in = BIO_new_file(key_id, "r");
	if (!in)
		return NULL;
	key = PEM_read_bio_PrivateKey(in, NULL, 0, NULL);
	BIO_free(in);
	return key;
	}
//MS: populate DATE_TIME_INFO struct with year,month, day,hour,minute,second,etc
static int ssl_get_ASN1_UTCTIME(const ASN1_UTCTIME *tm, DATE_TIME_INFO *dti)
{
    const char *v;
    int gmt=0;
    int i;
    int y=0,M=0,d=0,h=0,m=0,s=0;

    memset(dti, 0, sizeof(*dti));

    i=tm->length;
    v=(const char *)tm->data;

    if (i < 10) { goto err; }
    if (v[i-1] == 'Z') gmt=1;
    for (i=0; i<10; i++)
        if ((v[i] > '9') || (v[i] < '0')) { goto err; }
    y= (v[0]-'0')*10+(v[1]-'0');
    if (y < 50) y+=100;
    M= (v[2]-'0')*10+(v[3]-'0');
    if ((M > 12) || (M < 1)) { goto err; }
    d= (v[4]-'0')*10+(v[5]-'0');
    h= (v[6]-'0')*10+(v[7]-'0');
    m=  (v[8]-'0')*10+(v[9]-'0');
    if (tm->length >=12 &&
        (v[10] >= '0') && (v[10] <= '9') &&
        (v[11] >= '0') && (v[11] <= '9'))
        s=  (v[10]-'0')*10+(v[11]-'0');

    dti->year = SwapEndianIfBEc32(y+1900);
    dti->month = SwapEndianIfBEc32(M);
    dti->day = SwapEndianIfBEc32(d);
    dti->hour = SwapEndianIfBEc32(h);
    dti->minute = SwapEndianIfBEc32(m);
    dti->second = SwapEndianIfBEc32(s);
    dti->dlsTime = 0; //TODO:HOW to find
    dti->tzOffset = SwapEndianIfBEc32(gmt); //TODO:How to find

    return(1);

    
err:
    TINYCLR_SSL_PRINTF("Bad time value\r\n");
    return(0);
}
//MS: copied decoding algo from get_ASN1_UTCTIME of asn1_openssl.lib
//MS: populate DATE_TIME_INFO struct with year,month, day,hour,minute,second,etc
static int ssl_get_ASN1_UTCTIME(const ASN1_UTCTIME *tm, DATE_TIME_INFO *dti)
{
    const char *v;
    int gmt=0;
    int i;
    int y=0,M=0,d=0,h=0,m=0,s=0;

    i=SSL_LONG_LITTLE_ENDIAN(tm->length);
    v=(const char *)tm->data;

    if (i < 10) { goto err; }
    if (v[i-1] == 'Z') gmt=1;
    for (i=0; i<10; i++)
        if ((v[i] > '9') || (v[i] < '0')) { goto err; }
    y= (v[0]-'0')*10+(v[1]-'0');
    if (y < 50) y+=100;
    M= (v[2]-'0')*10+(v[3]-'0');
    if ((M > 12) || (M < 1)) { goto err; }
    d= (v[4]-'0')*10+(v[5]-'0');
    h= (v[6]-'0')*10+(v[7]-'0');
    m=  (v[8]-'0')*10+(v[9]-'0');
    if (tm->length >=12 &&
        (v[10] >= '0') && (v[10] <= '9') &&
        (v[11] >= '0') && (v[11] <= '9'))
        s=  (v[10]-'0')*10+(v[11]-'0');

    dti->year = y+1900;
    dti->month = M;
    dti->day = d;
    dti->hour = h;
    dti->minute = m;
    dti->second = s;
    dti->dlsTime = 0; //TODO:HOW to find
    dti->tzOffset = gmt; //TODO:How to find

    return(1);

    
err:
    TINYCLR_SSL_PRINTF("Bad time value\r\n");
    return(0);
}
Exemplo n.º 29
0
main()
{
	int i, prev = -1, bad = 0;
	X509V3_EXT_METHOD **tmp;
	i = sizeof(standard_exts) / sizeof(X509V3_EXT_METHOD *);
	if(i != STANDARD_EXTENSION_COUNT)
		TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR, "Extension number invalid expecting %d\n", i);
	tmp = standard_exts;
	for(i = 0; i < STANDARD_EXTENSION_COUNT; i++, tmp++) {
		if((*tmp)->ext_nid < prev) bad = 1;
		prev = (*tmp)->ext_nid;
		
	}
	if(bad) {
		tmp = standard_exts;
		TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR, "Extensions out of order!\n");
		for(i = 0; i < STANDARD_EXTENSION_COUNT; i++, tmp++)
		TINYCLR_SSL_PRINTF("%d : %s\n", (*tmp)->ext_nid, OBJ_nid2sn((*tmp)->ext_nid));
	} else TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR, "Order OK\n");
}
Exemplo n.º 30
0
int dtls1_enc(SSL *s, int send)
	{
	SSL3_RECORD *rec;
	EVP_CIPHER_CTX *ds;
	unsigned long l;
	int bs,i,ii,j,k,n=0;
	const EVP_CIPHER *enc;

	if (send)
		{
		if (EVP_MD_CTX_md(s->write_hash))
			{
			n=EVP_MD_CTX_size(s->write_hash);
			if (n < 0)
				return -1;
			}
		ds=s->enc_write_ctx;
		rec= &(s->s3->wrec);
		if (s->enc_write_ctx == NULL)
			enc=NULL;
		else
			{
			enc=EVP_CIPHER_CTX_cipher(s->enc_write_ctx);
			if ( rec->data != rec->input)
				/* we can't write into the input stream */
#ifndef OPENSSL_SYS_WINDOWS
				TINYCLR_SSL_PRINTF("%s:%d: rec->data != rec->input\n",
					__FILE__, __LINE__);

#else
				TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR, "%s:%d: rec->data != rec->input\n",
					__FILE__, __LINE__);
#endif
			else if ( EVP_CIPHER_block_size(ds->cipher) > 1)
				{
				if (RAND_bytes(rec->input, EVP_CIPHER_block_size(ds->cipher)) <= 0)
					return -1;
				}
			}
		}