[Ttssh2-commit] [7794] DSA構造体のメンバーアクセスが不可となったため、関数経由でのアクセスに変更した。

Zurück zum Archiv-Index
scmno****@osdn***** scmno****@osdn*****
2019年 6月 24日 (月) 12:12:03 JST


Revision: 7794
          https://osdn.net/projects/ttssh2/scm/svn/commits/7794
Author:   yutakapon
Date:     2019-06-24 12:12:02 +0900 (Mon, 24 Jun 2019)
Log Message:
-----------
DSA構造体のメンバーアクセスが不可となったため、関数経由でのアクセスに変更した。
チケット #36876 

Ticket Links:
------------
    https://osdn.net/projects/ttssh2/tracker/detail/36876

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

-------------- next part --------------
Modified: branches/openssl_1_1_1_v2/ttssh2/ttxssh/hosts.c
===================================================================
--- branches/openssl_1_1_1_v2/ttssh2/ttxssh/hosts.c	2019-06-23 07:55:34 UTC (rev 7793)
+++ branches/openssl_1_1_1_v2/ttssh2/ttxssh/hosts.c	2019-06-24 03:12:02 UTC (rev 7794)
@@ -863,6 +863,7 @@
 //    1 ... \x93\x99\x82\xB5\x82\xA2
 int HOSTS_compare_public_key(Key *src, Key *key)
 {
+	/********* OPENSSL1.1.1 NOTEST *********/
 	int bits;
 	unsigned char *exp;
 	unsigned char *mod;
@@ -871,6 +872,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;
 
 	/********* OPENSSL1.1.1 NOTEST *********/
 
@@ -900,11 +903,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_1_v2/ttssh2/ttxssh/key.c
===================================================================
--- branches/openssl_1_1_1_v2/ttssh2/ttxssh/key.c	2019-06-23 07:55:34 UTC (rev 7793)
+++ branches/openssl_1_1_1_v2/ttssh2/ttxssh/key.c	2019-06-24 03:12:02 UTC (rev 7794)
@@ -595,28 +595,35 @@
 //
 DSA *duplicate_DSA(DSA *src)
 {
+	/********* OPENSSL1.1.1 NOTEST *********/
 	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);
@@ -782,6 +789,7 @@
 {
 	/********* OPENSSL1.1.1 NOTEST *********/
 	BIGNUM *n = NULL;
+	BIGNUM *p = NULL;
 
 	switch (k->type) {
 	case KEY_RSA1:
@@ -790,7 +798,8 @@
 	case KEY_RSA:
 		return BN_num_bits(k->rsa->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:
@@ -1009,6 +1018,7 @@
 {
 	/********* OPENSSL1.1.1 NOTEST *********/
 	BIGNUM *d, *iqmp, *q, *p, *dmq1, *dmp1;
+	BIGNUM *priv_key = NULL;
 
 	d = iqmp = q = p = dmq1 = dmp1 = NULL;
 
@@ -1033,8 +1043,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;
 
@@ -1080,9 +1091,8 @@
 	}
 
 
-	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);
 	}
 
 }
@@ -1104,6 +1114,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)
@@ -1133,11 +1144,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;
@@ -1306,6 +1319,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);
@@ -1318,11 +1332,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:
@@ -1380,6 +1396,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;
@@ -1426,21 +1443,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();
+		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 ||
+		    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, q);
+		buffer_get_bignum2(&data, g);
+		buffer_get_bignum2(&data, pub_key);
 
 		hostkey->type = type;
 		hostkey->dsa = dsa;
@@ -1765,6 +1784,7 @@
 	Key *keypair;
 	char *s, *tmp;
 	BIGNUM *e = NULL, *n = NULL;
+	BIGNUM *p, *q, *g, *pub_key;
 
 	msg = buffer_init();
 	if (msg == NULL) {
@@ -1783,12 +1803,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:
@@ -1872,6 +1894,7 @@
 	/********* OPENSSL1.1.1 NOTEST *********/
 	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);
@@ -1891,11 +1914,13 @@
 			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:
@@ -1956,6 +1981,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)
@@ -1982,11 +2008,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_1_v2/ttssh2/ttxssh/keyfiles.c
===================================================================
--- branches/openssl_1_1_1_v2/ttssh2/ttxssh/keyfiles.c	2019-06-23 07:55:34 UTC (rev 7793)
+++ branches/openssl_1_1_1_v2/ttssh2/ttxssh/keyfiles.c	2019-06-24 03:12:02 UTC (rev 7794)
@@ -1154,6 +1154,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);
@@ -1169,26 +1171,28 @@
 			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;
 	}
@@ -1604,6 +1608,7 @@
 	case KEY_DSA:
 	{
 		int param;
+		BIGNUM *p, *q, *g, *pub_key, *priv_key;
 
 		result->dsa = DSA_new();
 		if (result->dsa == NULL) {
@@ -1610,16 +1615,18 @@
 			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;
 		}
@@ -1629,11 +1636,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_1_v2/ttssh2/ttxssh/ttxssh.c
===================================================================
--- branches/openssl_1_1_1_v2/ttssh2/ttxssh/ttxssh.c	2019-06-23 07:55:34 UTC (rev 7793)
+++ branches/openssl_1_1_1_v2/ttssh2/ttxssh/ttxssh.c	2019-06-24 03:12:02 UTC (rev 7794)
@@ -3476,6 +3476,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);
@@ -3491,19 +3493,24 @@
 		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;
 	}
@@ -4657,6 +4664,7 @@
 				char *uuenc; // uuencode data
 				int uulen;
 				BIGNUM *e, *n;
+				BIGNUM *p, *q, *g, *pub_key, *priv_key;
 				/********* OPENSSL1.1.1 NOTEST *********/
 
 				b = buffer_init();
@@ -4665,12 +4673,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 メーリングリストの案内
Zurück zum Archiv-Index