[Ttssh2-commit] [6567] DSA構造体のメンバーアクセスを関数アクセスに変更した。

svnno****@sourc***** svnno****@sourc*****
2017年 1月 9日 (月) 22:04:00 JST


Revision: 6567
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/6567
Author:   yutakapon
Date:     2017-01-09 22:04:00 +0900 (Mon, 09 Jan 2017)
Log Message:
-----------
DSA構造体のメンバーアクセスを関数アクセスに変更した。
ssh_rsa_verify関数でのRSA構造体の変更漏れを修正した。

Modified Paths:
--------------
    branches/openssl_1_1_0/ttssh2/ttxssh/hosts.c
    branches/openssl_1_1_0/ttssh2/ttxssh/key.c
    branches/openssl_1_1_0/ttssh2/ttxssh/keyfiles.c
    branches/openssl_1_1_0/ttssh2/ttxssh/ttxssh.c

-------------- next part --------------
Modified: branches/openssl_1_1_0/ttssh2/ttxssh/hosts.c
===================================================================
--- branches/openssl_1_1_0/ttssh2/ttxssh/hosts.c	2017-01-09 08:41:07 UTC (rev 6566)
+++ branches/openssl_1_1_0/ttssh2/ttxssh/hosts.c	2017-01-09 13:04:00 UTC (rev 6567)
@@ -984,6 +984,8 @@
 	Key *a, *b;
 	BIGNUM *e = NULL, *n = NULL;
 	BIGNUM *se = NULL, *sn = NULL;
+	BIGNUM *p, *q, *g, *pub_key;
+	BIGNUM *sp, *sq, *sg, *spub_key;
 
 	if (src->type != key->type) {
 		return -1;
@@ -1011,11 +1013,15 @@
 			BN_cmp(n, sn) == 0;
 
 	case KEY_DSA: // SSH2 DSA host public key
+		DSA_get0_pqg(key->dsa, &p, &q, &g);
+		DSA_get0_pqg(src->dsa, &sp, &sq, &sg);
+		DSA_get0_key(key->dsa, &pub_key, NULL);
+		DSA_get0_key(src->dsa, &spub_key, NULL);
 		return key->dsa != NULL && src->dsa &&
-			BN_cmp(key->dsa->p, src->dsa->p) == 0 &&
-			BN_cmp(key->dsa->q, src->dsa->q) == 0 &&
-			BN_cmp(key->dsa->g, src->dsa->g) == 0 &&
-			BN_cmp(key->dsa->pub_key, src->dsa->pub_key) == 0;
+			BN_cmp(p, sp) == 0 &&
+			BN_cmp(q, sq) == 0 &&
+			BN_cmp(g, sg) == 0 &&
+			BN_cmp(pub_key, spub_key) == 0;
 
 	case KEY_ECDSA256:
 	case KEY_ECDSA384:

Modified: branches/openssl_1_1_0/ttssh2/ttxssh/key.c
===================================================================
--- branches/openssl_1_1_0/ttssh2/ttxssh/key.c	2017-01-09 08:41:07 UTC (rev 6566)
+++ branches/openssl_1_1_0/ttssh2/ttxssh/key.c	2017-01-09 13:04:00 UTC (rev 6567)
@@ -258,6 +258,7 @@
 //	int rlen, ret, nid;
 	int ret = -1, nid;
 	char *ptr;
+	BIGNUM *n;
 
 	OpenSSL_add_all_digests();
 
@@ -268,7 +269,8 @@
 	if (key == NULL) {
 		return -2;
 	}
-	if (BN_num_bits(key->n) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
+	RSA_get0_key(key, &n, NULL, NULL);
+	if (BN_num_bits(n) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
 		return -3;
 	}
 	//debug_print(41, signature, signaturelen);
@@ -552,27 +554,34 @@
 DSA *duplicate_DSA(DSA *src)
 {
 	DSA *dsa = NULL;
+	BIGNUM *p, *q, *g, *pub_key;
+	BIGNUM *sp, *sq, *sg, *spub_key;
 
 	dsa = DSA_new();
 	if (dsa == NULL)
 		goto error;
-	dsa->p = BN_new();
-	dsa->q = BN_new();
-	dsa->g = BN_new();
-	dsa->pub_key = BN_new();
-	if (dsa->p == NULL ||
-	    dsa->q == NULL ||
-	    dsa->g == NULL ||
-	    dsa->pub_key == NULL) {
+	p = BN_new();
+	q = BN_new();
+	g = BN_new();
+	pub_key = BN_new();
+	DSA_set0_pqg(dsa, p, q, g);
+	DSA_set0_key(dsa, pub_key, NULL);
+
+	if (p == NULL ||
+	    q == NULL ||
+	    g == NULL ||
+	    pub_key == NULL) {
 		DSA_free(dsa);
 		goto error;
 	}
 
 	// \x90[\x82\xA2\x83R\x83s\x81[(deep copy)\x82\xF0\x8Ds\x82\xA4\x81B\x90󂢃R\x83s\x81[(shallow copy)\x82\xCDNG\x81B
-	BN_copy(dsa->p, src->p);
-	BN_copy(dsa->q, src->q);
-	BN_copy(dsa->g, src->g);
-	BN_copy(dsa->pub_key, src->pub_key);
+	DSA_get0_pqg(src, &sp, &sq, &sg);
+	DSA_get0_key(src, &spub_key, NULL);
+	BN_copy(p, sp);
+	BN_copy(q, sq);
+	BN_copy(g, sg);
+	BN_copy(pub_key, spub_key);
 
 error:
 	return (dsa);
@@ -734,6 +743,7 @@
 key_size(const Key *k)
 {
 	BIGNUM *n = NULL;
+	BIGNUM *p = NULL;
 
 	switch (k->type) {
 	case KEY_RSA1:
@@ -743,7 +753,8 @@
 		RSA_get0_key(k->rsa, &n, NULL, NULL);
 		return BN_num_bits(n);
 	case KEY_DSA:
-		return BN_num_bits(k->dsa->p);
+		DSA_get0_pqg(k->dsa, &p, NULL, NULL);
+		return BN_num_bits(p);
 	case KEY_ECDSA256:
 		return 256;
 	case KEY_ECDSA384:
@@ -961,6 +972,7 @@
 static void key_add_private(Key *k)
 {
 	BIGNUM *d, *iqmp, *q, *p, *dmq1, *dmp1;
+	BIGNUM *priv_key = NULL;
 
 	d = iqmp = q = p = dmq1 = dmp1 = NULL;
 
@@ -985,8 +997,9 @@
 			break;
 
 		case KEY_DSA:
-			k->dsa->priv_key = BN_new();
-			if (k->dsa->priv_key == NULL)
+			priv_key = BN_new();
+			DSA_set0_key(k->dsa, NULL, priv_key);
+			if (priv_key == NULL)
 				goto error;
 			break;
 
@@ -1031,9 +1044,9 @@
 	}
 
 
-	if (k->dsa->priv_key == NULL) {
-		BN_free(k->dsa->priv_key);
-		k->dsa->priv_key = NULL;
+	if (priv_key == NULL) {
+		BN_free(priv_key);
+		// DSA_set0_key\x8A֐\x94\x82ł̓\x81\x83\x93\x83o\x81[\x82\xC9NULL\x82\xF0\x83Z\x83b\x83g\x82\xB7\x82邱\x82Ƃ͂ł\xAB\x82Ȃ\xA2\x81B
 	}
 
 }
@@ -1054,6 +1067,7 @@
 	RSA *rsa;
 	DSA *dsa;
 	BIGNUM *e = NULL, *n = NULL;
+	BIGNUM *p, *q, *g, *pub_key, *priv_key;
 
 	k = calloc(1, sizeof(Key));
 	if (k == NULL)
@@ -1083,11 +1097,13 @@
 			dsa = DSA_new();
 			if (dsa == NULL)
 				goto error;
-			dsa->p = BN_new();
-			dsa->q = BN_new();
-			dsa->g = BN_new();
-			dsa->pub_key = BN_new();
-			if (dsa->p == NULL || dsa->q == NULL || dsa->g == NULL || dsa->pub_key == NULL)
+			p = BN_new();
+			q = BN_new();
+			g = BN_new();
+			DSA_set0_pqg(dsa, p, q, g);
+			pub_key = BN_new();
+			DSA_set0_key(dsa, pub_key, NULL);
+			if (p == NULL || q == NULL || g == NULL || pub_key == NULL)
 				goto error;
 			k->dsa = dsa;
 			break;
@@ -1255,6 +1271,7 @@
 	int len;
 	int ret = 1;  // success
 	BIGNUM *e = NULL, *n = NULL;
+	BIGNUM *p, *q, *g, *pub_key;
 
 	b = buffer_init();
 	sshname = get_sshname_from_key(key);
@@ -1267,11 +1284,13 @@
 		buffer_put_bignum2(b, n);
 		break;
 	case KEY_DSA:
+		DSA_get0_pqg(key->dsa, &p, &q, &g);
+		DSA_get0_key(key->dsa, &pub_key, NULL);
 		buffer_put_string(b, sshname, strlen(sshname));
-		buffer_put_bignum2(b, key->dsa->p);
-		buffer_put_bignum2(b, key->dsa->q);
-		buffer_put_bignum2(b, key->dsa->g);
-		buffer_put_bignum2(b, key->dsa->pub_key);
+		buffer_put_bignum2(b, p);
+		buffer_put_bignum2(b, q);
+		buffer_put_bignum2(b, g);
+		buffer_put_bignum2(b, pub_key);
 		break;
 	case KEY_ECDSA256:
 	case KEY_ECDSA384:
@@ -1328,6 +1347,7 @@
 	ssh_keytype type;
 	unsigned char *pk = NULL;
 	BIGNUM *e = NULL, *n = NULL;
+	BIGNUM *p, *dsa_q, *g, *pub_key;
 
 	if (data == NULL)
 		goto error;
@@ -1374,21 +1394,23 @@
 		if (dsa == NULL) {
 			goto error;
 		}
-		dsa->p = BN_new();
-		dsa->q = BN_new();
-		dsa->g = BN_new();
-		dsa->pub_key = BN_new();
-		if (dsa->p == NULL ||
-		    dsa->q == NULL ||
-		    dsa->g == NULL ||
-		    dsa->pub_key == NULL) {
+		p = BN_new();
+		dsa_q = BN_new();
+		g = BN_new();
+		pub_key = BN_new();
+		DSA_set0_pqg(dsa, p, dsa_q, g);
+		DSA_set0_key(dsa, pub_key, NULL);
+		if (p == NULL ||
+		    dsa_q == NULL ||
+		    g == NULL ||
+		    pub_key == NULL) {
 			goto error;
 		}
 
-		buffer_get_bignum2(&data, dsa->p);
-		buffer_get_bignum2(&data, dsa->q);
-		buffer_get_bignum2(&data, dsa->g);
-		buffer_get_bignum2(&data, dsa->pub_key);
+		buffer_get_bignum2(&data, p);
+		buffer_get_bignum2(&data, dsa_q);
+		buffer_get_bignum2(&data, g);
+		buffer_get_bignum2(&data, pub_key);
 
 		hostkey->type = type;
 		hostkey->dsa = dsa;
@@ -1697,6 +1719,7 @@
 	Key *keypair;
 	char *s, *tmp;
 	BIGNUM *e = NULL, *n = NULL;
+	BIGNUM *p, *q, *g, *pub_key;
 
 	msg = buffer_init();
 	if (msg == NULL) {
@@ -1715,12 +1738,14 @@
 		buffer_put_bignum2(msg, n); // p\x81~q
 		break;
 	case KEY_DSA: // DSA
+		DSA_get0_pqg(keypair->dsa, &p, &q, &g);
+		DSA_get0_key(keypair->dsa, &pub_key, NULL);
 		s = get_sshname_from_key(keypair);
 		buffer_put_string(msg, s, strlen(s));
-		buffer_put_bignum2(msg, keypair->dsa->p); // \x91f\x90\x94
-		buffer_put_bignum2(msg, keypair->dsa->q); // (p-1)\x82̑f\x88\xF6\x90\x94
-		buffer_put_bignum2(msg, keypair->dsa->g); // \x90\xAE\x90\x94
-		buffer_put_bignum2(msg, keypair->dsa->pub_key); // \x8C\xF6\x8AJ\x8C\xAE
+		buffer_put_bignum2(msg, p); // \x91f\x90\x94
+		buffer_put_bignum2(msg, q); // (p-1)\x82̑f\x88\xF6\x90\x94
+		buffer_put_bignum2(msg, g); // \x90\xAE\x90\x94
+		buffer_put_bignum2(msg, pub_key); // \x8C\xF6\x8AJ\x8C\xAE
 		break;
 	case KEY_ECDSA256: // ECDSA
 	case KEY_ECDSA384:
@@ -1803,6 +1828,7 @@
 {
 	char *s;
 	BIGNUM *e, *n, *d, *iqmp, *p, *q;
+	BIGNUM *g, *pub_key, *priv_key;
 	
 	s = get_sshname_from_key(key);
 	buffer_put_cstring(b, s);
@@ -1822,11 +1848,14 @@
 			break;
 
 		case KEY_DSA:
-			buffer_put_bignum2(b, key->dsa->p);
-			buffer_put_bignum2(b, key->dsa->q);
-			buffer_put_bignum2(b, key->dsa->g);
-			buffer_put_bignum2(b, key->dsa->pub_key);
-			buffer_put_bignum2(b, key->dsa->priv_key);
+			DSA_get0_pqg(key->dsa, &p, &q, &g);
+			DSA_get0_key(key->dsa, &pub_key, &priv_key);
+
+			buffer_put_bignum2(b, p);
+			buffer_put_bignum2(b, q);
+			buffer_put_bignum2(b, g);
+			buffer_put_bignum2(b, pub_key);
+			buffer_put_bignum2(b, priv_key);
 			break;
 
 		case KEY_ECDSA256:
@@ -1921,6 +1950,7 @@
 	unsigned int pklen, sklen;
 	int type;
 	BIGNUM *e, *n, *d, *dmp1, *dmq1, *iqmp, *p, *q;
+	BIGNUM *g, *pub_key, *priv_key;
 
 	type_name = buffer_get_string_msg(blob, NULL);
 	if (type_name == NULL)
@@ -1947,11 +1977,13 @@
 			break;
 
 		case KEY_DSA:
-			buffer_get_bignum2_msg(blob, k->dsa->p);
-			buffer_get_bignum2_msg(blob, k->dsa->q);
-			buffer_get_bignum2_msg(blob, k->dsa->g);
-			buffer_get_bignum2_msg(blob, k->dsa->pub_key);
-			buffer_get_bignum2_msg(blob, k->dsa->priv_key);
+			DSA_get0_pqg(k->dsa, &p, &q, &g);
+			DSA_get0_key(k->dsa, &pub_key, &priv_key);
+			buffer_get_bignum2_msg(blob, p);
+			buffer_get_bignum2_msg(blob, q);
+			buffer_get_bignum2_msg(blob, g);
+			buffer_get_bignum2_msg(blob, pub_key);
+			buffer_get_bignum2_msg(blob, priv_key);
 			break;
 
 		case KEY_ECDSA256:

Modified: branches/openssl_1_1_0/ttssh2/ttxssh/keyfiles.c
===================================================================
--- branches/openssl_1_1_0/ttssh2/ttxssh/keyfiles.c	2017-01-09 08:41:07 UTC (rev 6566)
+++ branches/openssl_1_1_0/ttssh2/ttxssh/keyfiles.c	2017-01-09 13:04:00 UTC (rev 6567)
@@ -1092,6 +1092,8 @@
 	case KEY_DSA:
 	{
 		char *pubkey_type, *pub, *pri;
+		BIGNUM *p, *q, *g, *pub_key, *priv_key;
+
 		pub = pubkey->buf;
 		pri = prikey->buf;
 		pubkey_type = buffer_get_string(&pub, NULL);
@@ -1107,26 +1109,30 @@
 			strncpy_s(errmsg, errmsg_len, "key init error", _TRUNCATE);
 			goto error;
 		}
-		result->dsa->p = BN_new();
-		result->dsa->q = BN_new();
-		result->dsa->g = BN_new();
-		result->dsa->pub_key = BN_new();
-		result->dsa->priv_key = BN_new();
-		if (result->dsa->p == NULL ||
-		    result->dsa->q == NULL ||
-		    result->dsa->g == NULL ||
-		    result->dsa->pub_key == NULL ||
-		    result->dsa->priv_key == NULL) {
+		p = BN_new();
+		q = BN_new();
+		g = BN_new();
+		DSA_set0_pqg(result->dsa, p, q, g);
+
+		pub_key = BN_new();
+		priv_key = BN_new();
+		DSA_set0_key(result->dsa, pub_key, priv_key);
+
+		if (p == NULL ||
+		    q == NULL ||
+		    g == NULL ||
+		    pub_key == NULL ||
+		    priv_key == NULL) {
 			strncpy_s(errmsg, errmsg_len, "key init error", _TRUNCATE);
 			goto error;
 		}
 
-		buffer_get_bignum2(&pub, result->dsa->p);
-		buffer_get_bignum2(&pub, result->dsa->q);
-		buffer_get_bignum2(&pub, result->dsa->g);
-		buffer_get_bignum2(&pub, result->dsa->pub_key);
+		buffer_get_bignum2(&pub, p);
+		buffer_get_bignum2(&pub, q);
+		buffer_get_bignum2(&pub, g);
+		buffer_get_bignum2(&pub, pub_key);
 
-		buffer_get_bignum2(&pri, result->dsa->priv_key);
+		buffer_get_bignum2(&pri, priv_key);
 
 		break;
 	}
@@ -1439,6 +1445,7 @@
 	case KEY_DSA:
 	{
 		int param;
+		BIGNUM *p, *q, *g, *pub_key, *priv_key;
 
 		result->dsa = DSA_new();
 		if (result->dsa == NULL) {
@@ -1445,16 +1452,20 @@
 			strncpy_s(errmsg, errmsg_len, "key init error", _TRUNCATE);
 			goto error;
 		}
-		result->dsa->p = BN_new();
-		result->dsa->q = BN_new();
-		result->dsa->g = BN_new();
-		result->dsa->pub_key = BN_new();
-		result->dsa->priv_key = BN_new();
-		if (result->dsa->p == NULL ||
-		    result->dsa->q == NULL ||
-		    result->dsa->g == NULL ||
-		    result->dsa->pub_key == NULL ||
-		    result->dsa->priv_key == NULL) {
+		p = BN_new();
+		q = BN_new();
+		g = BN_new();
+		DSA_set0_pqg(result->dsa, p, q, g);
+
+		pub_key = BN_new();
+		priv_key = BN_new();
+		DSA_set0_key(result->dsa, pub_key, priv_key);
+
+		if (p == NULL ||
+		    q == NULL ||
+		    g == NULL ||
+		    pub_key == NULL ||
+		    priv_key == NULL) {
 			strncpy_s(errmsg, errmsg_len, "key init error", _TRUNCATE);
 			goto error;
 		}
@@ -1464,11 +1475,11 @@
 			strncpy_s(errmsg, errmsg_len, "predefined DSA parameters not supported", _TRUNCATE);
 			goto error;
 		}
-		buffer_get_bignum_SECSH(blob2, result->dsa->p);
-		buffer_get_bignum_SECSH(blob2, result->dsa->g);
-		buffer_get_bignum_SECSH(blob2, result->dsa->q);
-		buffer_get_bignum_SECSH(blob2, result->dsa->pub_key);
-		buffer_get_bignum_SECSH(blob2, result->dsa->priv_key);
+		buffer_get_bignum_SECSH(blob2, p);
+		buffer_get_bignum_SECSH(blob2, g);
+		buffer_get_bignum_SECSH(blob2, q);
+		buffer_get_bignum_SECSH(blob2, pub_key);
+		buffer_get_bignum_SECSH(blob2, priv_key);
 
 		break;
 	}

Modified: branches/openssl_1_1_0/ttssh2/ttxssh/ttxssh.c
===================================================================
--- branches/openssl_1_1_0/ttssh2/ttxssh/ttxssh.c	2017-01-09 08:41:07 UTC (rev 6566)
+++ branches/openssl_1_1_0/ttssh2/ttxssh/ttxssh.c	2017-01-09 13:04:00 UTC (rev 6567)
@@ -3688,6 +3688,8 @@
 	{
 		DSA *priv = NULL;
 		DSA *pub = NULL;
+		BIGNUM *p, *q, *g, *pub_key;
+		BIGNUM *sp, *sq, *sg, *spub_key;
 
 		// private key
 		priv = DSA_generate_parameters(bits, NULL, 0, NULL, NULL, cbfunc, cbarg);
@@ -3703,19 +3705,25 @@
 		pub = DSA_new();
 		if (pub == NULL)
 			goto error;
-		pub->p = BN_new();
-		pub->q = BN_new();
-		pub->g = BN_new();
-		pub->pub_key = BN_new();
-		if (pub->p == NULL || pub->q == NULL || pub->g == NULL || pub->pub_key == NULL) {
+		p = BN_new();
+		q = BN_new();
+		g = BN_new();
+		DSA_set0_pqg(pub, p, q, g);
+
+		pub_key = BN_new();
+		DSA_set0_key(pub, pub_key, NULL);
+		if (p == NULL || q == NULL || g == NULL || pub_key == NULL) {
 			DSA_free(pub);
 			goto error;
 		}
 
-		BN_copy(pub->p, priv->p);
-		BN_copy(pub->q, priv->q);
-		BN_copy(pub->g, priv->g);
-		BN_copy(pub->pub_key, priv->pub_key);
+		DSA_get0_pqg(priv, &sp, &sq, &sg);
+		DSA_get0_key(priv, &spub_key, NULL);
+
+		BN_copy(p, sp);
+		BN_copy(q, sq);
+		BN_copy(g, sg);
+		BN_copy(pub_key, spub_key);
 		public_key.dsa = pub;
 		break;
 	}
@@ -4906,6 +4914,7 @@
 				char *uuenc; // uuencode data
 				int uulen;
 				BIGNUM *e, *n;
+				BIGNUM *p, *q, *g, *pub_key, *priv_key;
 
 				b = buffer_init();
 				if (b == NULL)
@@ -4913,12 +4922,15 @@
 
 				switch (public_key.type) {
 				case KEY_DSA: // DSA
+					DSA_get0_pqg(dsa, &p, &q, &g);
+					DSA_get0_key(dsa, &pub_key, NULL);
+
 					keyname = "ssh-dss";
 					buffer_put_string(b, keyname, strlen(keyname));
-					buffer_put_bignum2(b, dsa->p);
-					buffer_put_bignum2(b, dsa->q);
-					buffer_put_bignum2(b, dsa->g);
-					buffer_put_bignum2(b, dsa->pub_key);
+					buffer_put_bignum2(b, p);
+					buffer_put_bignum2(b, q);
+					buffer_put_bignum2(b, g);
+					buffer_put_bignum2(b, pub_key);
 					break;
 
 				case KEY_RSA: // RSA



Ttssh2-commit メーリングリストの案内