pgsqlclient-checkins Mailing List for PostgreSqlClient (Page 16)
Status: Inactive
Brought to you by:
carlosga_fb
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(120) |
Aug
(95) |
Sep
(95) |
Oct
(213) |
Nov
(114) |
Dec
(64) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(6) |
Feb
(134) |
Mar
(88) |
Apr
(28) |
May
(22) |
Jun
(15) |
Jul
(23) |
Aug
(2) |
Sep
(15) |
Oct
(2) |
Nov
(6) |
Dec
|
2005 |
Jan
(8) |
Feb
(6) |
Mar
|
Apr
(42) |
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
(84) |
Oct
|
Nov
|
Dec
|
2006 |
Jan
|
Feb
|
Mar
(84) |
Apr
(46) |
May
(40) |
Jun
(8) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Carlos G. Á. <car...@us...> - 2004-06-12 09:27:59
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Math.Prime In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1264 Modified Files: PrimalityTests.cs Log Message: Updated Mono.Security sources to mono Beta 2 Index: PrimalityTests.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Math.Prime/PrimalityTests.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PrimalityTests.cs 9 May 2004 11:59:12 -0000 1.2 --- PrimalityTests.cs 12 Jun 2004 09:27:51 -0000 1.3 *************** *** 62,68 **** return Rounds; case ConfidenceFactor.High: ! return Rounds <<= 1; case ConfidenceFactor.ExtraHigh: ! return Rounds <<= 2; case ConfidenceFactor.Provable: throw new Exception ("The Rabin-Miller test can not be executed in a way such that its results are provable"); --- 62,68 ---- return Rounds; case ConfidenceFactor.High: ! return Rounds << 1; case ConfidenceFactor.ExtraHigh: ! return Rounds << 2; case ConfidenceFactor.Provable: throw new Exception ("The Rabin-Miller test can not be executed in a way such that its results are provable"); *************** *** 107,125 **** BigInteger a = null; BigInteger.ModulusRing mr = new BigInteger.ModulusRing (bi); ! for (int round = 0; round < Rounds; round++) { while (true) { // generate a < n a = BigInteger.GenerateRandom (bits); ! // make sure "a" is not 0 ! if (a > 1 && a < bi) break; } ! if (a.GCD (bi) != 1) return false; ! BigInteger b = mr.Pow (a, t); ! if (b == 1) continue; // a^t mod p = 1 bool result = false; --- 107,145 ---- BigInteger a = null; BigInteger.ModulusRing mr = new BigInteger.ModulusRing (bi); + + // Applying optimization from HAC section 4.50 (base == 2) + // not a really random base but an interesting (and speedy) one + BigInteger b = mr.Pow (2, t); + if (b != 1) { + bool result = false; + for (int j=0; j < s; j++) { + if (b == p_sub1) { // a^((2^j)*t) mod p = p-1 for some 0 <= j <= s-1 + result = true; + break; + } ! b = (b * b) % bi; ! } ! if (!result) ! return false; ! } ! ! // still here ? start at round 1 (round 0 was a == 2) ! for (int round = 1; round < Rounds; round++) { while (true) { // generate a < n a = BigInteger.GenerateRandom (bits); ! // make sure "a" is not 0 (and not 2 as we have already tested that) ! if (a > 2 && a < bi) break; } ! if (a.GCD (bi) != 1) ! return false; ! b = mr.Pow (a, t); ! if (b == 1) ! continue; // a^t mod p = 1 bool result = false; *************** *** 134,138 **** } ! if (result == false) return false; } --- 154,158 ---- } ! if (!result) return false; } *************** *** 174,178 **** } return true; - } --- 194,197 ---- |
From: Carlos G. Á. <car...@us...> - 2004-06-12 09:27:40
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Math In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1044 Modified Files: BigInteger.cs Log Message: Updated Mono.Security sources to mono Beta 2 Index: BigInteger.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Math/BigInteger.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BigInteger.cs 9 May 2004 11:58:48 -0000 1.2 --- BigInteger.cs 12 Jun 2004 09:27:31 -0000 1.3 *************** *** 835,843 **** public bool IsProbablePrime () { ! for (int p = 0; p < smallPrimes.Length; p++) { ! if (this == smallPrimes [p]) ! return true; ! if (this % smallPrimes [p] == 0) ! return false; } return PrimalityTests.RabinMillerTest (this, Prime.ConfidenceFactor.Medium); --- 835,849 ---- public bool IsProbablePrime () { ! if (this < smallPrimes [smallPrimes.Length - 1]) { ! for (int p = 0; p < smallPrimes.Length; p++) { ! if (this == smallPrimes [p]) ! return true; ! } ! } ! else { ! for (int p = 0; p < smallPrimes.Length; p++) { ! if (this % smallPrimes [p] == 0) ! return false; ! } } return PrimalityTests.RabinMillerTest (this, Prime.ConfidenceFactor.Medium); *************** *** 1096,1106 **** public BigInteger Pow (uint b, BigInteger exp) { ! if (b != 2) { ! if ((mod.data [0] & 1) == 1) return OddPow (b, exp); ! else return EvenPow (b, exp); } else { ! if ((mod.data [0] & 1) == 1) return OddModTwoPow (exp); ! else return EvenModTwoPow (exp); ! } } --- 1102,1117 ---- public BigInteger Pow (uint b, BigInteger exp) { ! // if (b != 2) { ! if ((mod.data [0] & 1) == 1) ! return OddPow (b, exp); ! else ! return EvenPow (b, exp); ! /* buggy in some cases (like the well tested primes) } else { ! if ((mod.data [0] & 1) == 1) ! return OddModTwoPow (exp); ! else ! return EvenModTwoPow (exp); ! }*/ } *************** *** 1166,1171 **** // We would rather have this estimate overshoot, // so we add one to the divisor ! uint divEstimate = (uint) ((((ulong)cc << 32) | (ulong) u [i -1]) / ! (mod.data [mod.length-1] + 1)); uint t; --- 1177,1190 ---- // We would rather have this estimate overshoot, // so we add one to the divisor ! uint divEstimate; ! if (mod.data [mod.length - 1] < UInt32.MaxValue) { ! divEstimate = (uint) ((((ulong)cc << 32) | (ulong) u [i -1]) / ! (mod.data [mod.length-1] + 1)); ! } ! else { ! // guess but don't divide by 0 ! divEstimate = (uint) ((((ulong)cc << 32) | (ulong) u [i -1]) / ! (mod.data [mod.length-1])); ! } uint t; *************** *** 1309,1312 **** --- 1328,1332 ---- } + /* known to be buggy in some cases private unsafe BigInteger EvenModTwoPow (BigInteger exp) { *************** *** 1441,1445 **** return resultNum; } ! #endregion } --- 1461,1465 ---- return resultNum; } ! */ #endregion } |
From: Carlos G. Á. <car...@us...> - 2004-06-12 09:26:32
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32557 Modified Files: X509Chain.cs X509Certificate.cs PKCS12.cs Log Message: Updated Mono.Security sources to mono Beta 2 Index: X509Certificate.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/X509Certificate.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** X509Certificate.cs 9 May 2004 12:06:15 -0000 1.3 --- X509Certificate.cs 12 Jun 2004 09:26:20 -0000 1.4 *************** *** 175,180 **** m_encodedcert = (byte[]) data.Clone (); } ! catch { ! throw new CryptographicException (e); } } --- 175,180 ---- m_encodedcert = (byte[]) data.Clone (); } ! catch (Exception ex) { ! throw new CryptographicException (e, ex); } } *************** *** 454,456 **** } } ! } \ No newline at end of file --- 454,456 ---- } } ! } Index: X509Chain.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/X509Chain.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** X509Chain.cs 9 May 2004 12:06:15 -0000 1.3 --- X509Chain.cs 12 Jun 2004 09:26:20 -0000 1.4 *************** *** 183,190 **** return false; } ! // TODO - we should check for CRITICAL but unknown extensions // X509ChainStatusFlags.InvalidExtension - /* #if (!NET_1_0 && !INSIDE_CORLIB) if (ServicePointManager.CheckCertificateRevocationList) { --- 183,189 ---- return false; } ! /* // TODO - we should check for CRITICAL but unknown extensions // X509ChainStatusFlags.InvalidExtension #if (!NET_1_0 && !INSIDE_CORLIB) if (ServicePointManager.CheckCertificateRevocationList) { Index: PKCS12.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/PKCS12.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PKCS12.cs 9 May 2004 12:06:15 -0000 1.2 --- PKCS12.cs 12 Jun 2004 09:26:20 -0000 1.3 *************** *** 45,49 **** public #endif ! class PKCS12 { public const string pbeWithSHAAnd128BitRC4 = "1.2.840.113549.1.12.1.1"; --- 45,82 ---- public #endif ! class PKCS9 { ! [...1161 lines suppressed...] *************** *** 756,759 **** --- 1658,1674 ---- } + public object Clone () + { + PKCS12 clone = null; + if (_password != null) { + clone = new PKCS12 (GetBytes (), Encoding.BigEndianUnicode.GetString (_password)); + } else { + clone = new PKCS12 (GetBytes ()); + } + clone.IterationCount = this.IterationCount; + + return clone; + } + // static methods |
From: Carlos G. Á. <car...@us...> - 2004-06-12 09:25:48
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32130 Removed Files: TestAnchors.cs Log Message: 2004-06-12 Carlos Guzman Alvarez <car...@te...> * FirebirdSql.Data.Gds/GdsStatement.cs: - Fixed bug in Fetch method when working with statements using EXECUTE PROCEDURE syntax. --- TestAnchors.cs DELETED --- |
From: Carlos G. Á. <car...@us...> - 2004-06-10 08:35:36
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15448 Modified Files: changelog.txt Log Message: Fix for PgCommand.NextResult (Thanks to Sion for his feedback) Index: changelog.txt =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/changelog.txt,v retrieving revision 1.119 retrieving revision 1.120 diff -C2 -d -r1.119 -r1.120 *** changelog.txt 3 Jun 2004 16:39:17 -0000 1.119 --- changelog.txt 10 Jun 2004 08:34:10 -0000 1.120 *************** *** 3,6 **** --- 3,12 ---- + 2004-06-09 Carlos Guzman Alvarez <car...@te...> + + * PostgreSql.Data.PgSqlClient/PgCommand.cs: + + - Fix for PgCommand.NextResult (Thanks to Sion for his feedback) + 2004-06-03 Carlos Guzman Alvarez <car...@te...> |
From: Carlos G. Á. <car...@us...> - 2004-06-10 08:33:11
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13670 Modified Files: PgCommand.cs Log Message: Fix for PgCommand.NextResult (Thanks to Sion for his feedback) Index: PgCommand.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgCommand.cs,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** PgCommand.cs 3 May 2004 20:30:15 -0000 1.36 --- PgCommand.cs 10 Jun 2004 08:33:01 -0000 1.37 *************** *** 545,550 **** this.statement = null; ! if ((this.commandBehavior & CommandBehavior.SingleResult) == CommandBehavior.SingleResult || ! this.commandBehavior == System.Data.CommandBehavior.Default) { this.actualCommand++; --- 545,549 ---- this.statement = null; ! if ((behavior & CommandBehavior.SingleResult) != CommandBehavior.SingleResult) { this.actualCommand++; *************** *** 557,561 **** { string commandText = this.commands[actualCommand]; - if (commandText != null && commandText.Trim().Length > 0) { --- 556,559 ---- |
From: Carlos G. Á. <car...@us...> - 2004-06-03 16:39:25
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11975 Modified Files: changelog.txt Log Message: 2004-06-03 Carlos Guzman Alvarez <car...@te...> * PostgreSql.Data.PgSqlClient/PgLayouts.cs: - Removed file. * PostgreSql.Data.PgSqlClient/PgResponsePacket.cs: * PostgreSql.Data.PgSqlClient/PgOutputPacket.cs: - Improved Doubvle and Float read/write Index: changelog.txt =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/changelog.txt,v retrieving revision 1.118 retrieving revision 1.119 diff -C2 -d -r1.118 -r1.119 *** changelog.txt 31 May 2004 17:20:14 -0000 1.118 --- changelog.txt 3 Jun 2004 16:39:17 -0000 1.119 *************** *** 3,6 **** --- 3,17 ---- + 2004-06-03 Carlos Guzman Alvarez <car...@te...> + + * PostgreSql.Data.PgSqlClient/PgLayouts.cs: + + - Removed file. + + * PostgreSql.Data.PgSqlClient/PgResponsePacket.cs: + * PostgreSql.Data.PgSqlClient/PgOutputPacket.cs: + + - Improved Doubvle and Float read/write + 2004-05-31 Carlos Guzman Alvarez <car...@te...> |
From: Carlos G. Á. <car...@us...> - 2004-06-03 16:39:05
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11895 Removed Files: PgLayouts.cs Log Message: 2004-06-03 Carlos Guzman Alvarez <car...@te...> * PostgreSql.Data.PgSqlClient/PgLayouts.cs: - Removed file. * PostgreSql.Data.PgSqlClient/PgResponsePacket.cs: * PostgreSql.Data.PgSqlClient/PgOutputPacket.cs: - Improved Doubvle and Float read/write --- PgLayouts.cs DELETED --- |
From: Carlos G. Á. <car...@us...> - 2004-06-03 16:37:29
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11574 Modified Files: PgOutputPacket.cs PgResponsePacket.cs Log Message: 2004-06-03 Carlos Guzman Alvarez <car...@te...> * PostgreSql.Data.PgSqlClient/PgLayouts.cs: - Removed file. * PostgreSql.Data.PgSqlClient/PgResponsePacket.cs: * PostgreSql.Data.PgSqlClient/PgOutputPacket.cs: - Improved Doubvle and Float read/write Index: PgResponsePacket.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient/PgResponsePacket.cs,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** PgResponsePacket.cs 10 Apr 2004 20:16:07 -0000 1.25 --- PgResponsePacket.cs 3 Jun 2004 16:37:20 -0000 1.26 *************** *** 173,181 **** public override float ReadSingle() ! { FloatLayout floatValue = new FloatLayout(); floatValue.i0 = IPAddress.HostToNetworkOrder(base.ReadInt32()); return floatValue.f; } --- 173,185 ---- public override float ReadSingle() ! { ! return BitConverter.ToSingle(BitConverter.GetBytes(this.ReadInt()), 0); ! ! /* FloatLayout floatValue = new FloatLayout(); floatValue.i0 = IPAddress.HostToNetworkOrder(base.ReadInt32()); return floatValue.f; + */ } *************** *** 188,192 **** public override double ReadDouble() ! { DoubleLayout doubleValue = new DoubleLayout(); int temp; --- 192,199 ---- public override double ReadDouble() ! { ! return BitConverter.ToDouble(BitConverter.GetBytes(this.ReadLong()), 0); ! ! /* DoubleLayout doubleValue = new DoubleLayout(); int temp; *************** *** 201,204 **** --- 208,212 ---- return doubleValue.d; + */ } Index: PgOutputPacket.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient/PgOutputPacket.cs,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** PgOutputPacket.cs 3 May 2004 20:29:36 -0000 1.25 --- PgOutputPacket.cs 3 Jun 2004 16:37:20 -0000 1.26 *************** *** 99,124 **** public void WriteFloat(float val) { ! FloatLayout floatValue = new FloatLayout(); ! ! floatValue.f = val; ! floatValue.i0 = IPAddress.HostToNetworkOrder(floatValue.i0); ! this.Write(floatValue.f); } public void WriteDouble(double val) { ! DoubleLayout doubleValue = new DoubleLayout(); ! int temp; ! ! doubleValue.d = val; ! doubleValue.i0 = IPAddress.HostToNetworkOrder(doubleValue.i0); ! doubleValue.i4 = IPAddress.HostToNetworkOrder(doubleValue.i4); ! ! temp = doubleValue.i0; ! doubleValue.i0 = doubleValue.i4; ! doubleValue.i4 = temp; ! this.Write(doubleValue.d); } --- 99,112 ---- public void WriteFloat(float val) { ! byte[] buffer = BitConverter.GetBytes(val); ! this.Write(BitConverter.ToInt32(buffer, 0)); } public void WriteDouble(double val) { ! byte[] buffer = BitConverter.GetBytes(val); ! this.Write(BitConverter.ToInt64(buffer, 0)); } |
From: Carlos Guzm?n ?l. <car...@us...> - 2004-05-31 17:20:23
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13964 Modified Files: changelog.txt Log Message: 2004-05-31 Carlos Guzman Alvarez <car...@te...> * PostgreSql.Data.PgSqlClient/FbConnection.cs: * PostgreSql.Data.PgSqlClient/NPgClient/PgDbClient.cs: - Reworked information and notification message handling using callbacks (delegates) Index: changelog.txt =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/changelog.txt,v retrieving revision 1.117 retrieving revision 1.118 diff -C2 -d -r1.117 -r1.118 *** changelog.txt 9 May 2004 12:09:55 -0000 1.117 --- changelog.txt 31 May 2004 17:20:14 -0000 1.118 *************** *** 3,9 **** 2004-05-09 Carlos Guzman Alvarez <car...@te...> ! * Symc Mono.Security stuff with mono beta 1 sources. 2004-05-06 Carlos Guzman Alvarez <car...@te...> --- 3,18 ---- + 2004-05-31 Carlos Guzman Alvarez <car...@te...> + + * PostgreSql.Data.PgSqlClient/FbConnection.cs: + * PostgreSql.Data.PgSqlClient/NPgClient/PgDbClient.cs: + + - Reworked information and notification message handling + using callbacks (delegates) + + 2004-05-09 Carlos Guzman Alvarez <car...@te...> ! * Sync Mono.Security stuff with mono beta 1 sources. 2004-05-06 Carlos Guzman Alvarez <car...@te...> |
From: Carlos Guzm?n ?l. <car...@us...> - 2004-05-31 17:20:03
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13825 Modified Files: PgDbClient.cs Log Message: 2004-05-31 Carlos Guzman Alvarez <car...@te...> * PostgreSql.Data.PgSqlClient/FbConnection.cs: * PostgreSql.Data.PgSqlClient/NPgClient/PgDbClient.cs: - Reworked information and notification message handling using callbacks (delegates) Index: PgDbClient.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient/PgDbClient.cs,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** PgDbClient.cs 6 May 2004 08:17:16 -0000 1.48 --- PgDbClient.cs 31 May 2004 17:19:55 -0000 1.49 *************** *** 33,36 **** --- 33,38 ---- internal delegate void SslConnectionCallback(); + internal delegate void NotificationCallback(int processID, string condition, string aditional); + internal delegate void InfoMessageCallback(PgClientException exception); #endregion *************** *** 38,46 **** internal class PgDbClient { ! #region Events ! public event PgClientMessageEventHandler InfoMessage; ! public event PgClientNotificationEventHandler Notification; ! public event SslConnectionCallback SslConnection; #endregion --- 40,62 ---- internal class PgDbClient { ! #region Callbacks ! public SslConnectionCallback SslConnection ! { ! get { return this.sslCallback; } ! set { this.sslCallback = value; } ! } ! ! public NotificationCallback Notification ! { ! get { return this.notification; } ! set { this.notification = value; } ! } ! ! public InfoMessageCallback InfoMessage ! { ! get { return this.infoMessage; } ! set { this.infoMessage = value; } ! } #endregion *************** *** 53,72 **** #endregion - #region Fields - - private int handle; - private int secretKey; - private Hashtable parameterStatus; - private Socket socket; - private NetworkStream networkStream; - private SslClientStream sslStream; - private BinaryReader receive; - private BinaryWriter send; - private PgResponsePacket buffer; - private PgConnectionParams settings; - private char transactionStatus; - - #endregion - #region Static Properties --- 69,72 ---- *************** *** 85,88 **** --- 85,108 ---- #endregion + #region Fields + + private SslConnectionCallback sslCallback; + private NotificationCallback notification; + private InfoMessageCallback infoMessage; + + private int handle; + private int secretKey; + private Hashtable parameterStatus; + private Socket socket; + private NetworkStream networkStream; + private SslClientStream sslStream; + private BinaryReader receive; + private BinaryWriter send; + private PgResponsePacket buffer; + private PgConnectionParams settings; + private char transactionStatus; + + #endregion + #region Properties *************** *** 111,120 **** } - public SslConnectionCallback SslConnectionDelegate - { - get { return this.SslConnection; } - set { this.SslConnection = value; } - } - #endregion --- 131,134 ---- *************** *** 292,296 **** { case PgBackendCodes.ERROR_RESPONSE: - { // Read the error message and trow the exception PgClientException ex = processErrorPacket(responsePacket); --- 306,309 ---- *************** *** 299,313 **** this.Sync(); throw ex; - } case PgBackendCodes.NOTICE_RESPONSE: - { // Read the notice message and raise an InfoMessage event ! PgClientException ex = processErrorPacket(responsePacket); ! ! this.InfoMessage(this, new PgClientMessageEventArgs(ex)); ! } ! break; case PgBackendCodes.NOTIFICATION_RESPONSE: --- 312,322 ---- this.Sync(); + // Throe the PostgreSQL exception throw ex; case PgBackendCodes.NOTICE_RESPONSE: // Read the notice message and raise an InfoMessage event ! this.InfoMessage(processErrorPacket(responsePacket)); ! break; case PgBackendCodes.NOTIFICATION_RESPONSE: *************** *** 512,516 **** if (this.Notification != null) { ! this.Notification(this, new PgClientNotificationEventArgs(processID, condition, additional)); } } --- 521,525 ---- if (this.Notification != null) { ! this.Notification(processID, condition, additional); } } *************** *** 816,820 **** if (this.InfoMessage != null) { ! this.InfoMessage(this, new PgClientMessageEventArgs(exception)); } } --- 825,829 ---- if (this.InfoMessage != null) { ! this.InfoMessage(exception); } } |
From: Carlos Guzm?n ?l. <car...@us...> - 2004-05-31 17:19:09
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13556 Modified Files: PgConnection.cs Log Message: 2004-05-31 Carlos Guzman Alvarez <car...@te...> * PostgreSql.Data.PgSqlClient/FbConnection.cs: * PostgreSql.Data.PgSqlClient/NPgClient/PgDbClient.cs: - Reworked information and notification message handling using callbacks (delegates) Index: PgConnection.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgConnection.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** PgConnection.cs 10 Apr 2004 20:15:33 -0000 1.17 --- PgConnection.cs 31 May 2004 17:18:57 -0000 1.18 *************** *** 59,65 **** private ArrayList activeCommands; - private PgClientMessageEventHandler infoMessageHandler; - private PgClientNotificationEventHandler notificationHandler; - #endregion --- 59,62 ---- *************** *** 202,206 **** #region Constructors ! public PgConnection() : base() { this.state = ConnectionState.Closed; --- 199,207 ---- #region Constructors ! public PgConnection() : this(null) ! { ! } ! ! public PgConnection(string connString) : base() { this.state = ConnectionState.Closed; *************** *** 208,216 **** GC.SuppressFinalize(this); ! } ! ! public PgConnection(string connString) : this() ! { ! this.ConnectionString = connString; } --- 209,217 ---- GC.SuppressFinalize(this); ! ! if (connString != null) ! { ! this.ConnectionString = connString; ! } } *************** *** 381,385 **** // Add handler for Ssl connections ! dbConnection.DB.SslConnectionDelegate = new SslConnectionCallback(this.OnSslConnection); // Open connection --- 382,386 ---- // Add handler for Ssl connections ! dbConnection.DB.SslConnection = new SslConnectionCallback(this.OnSslConnection); // Open connection *************** *** 397,401 **** // Set connection state to Open ! this.state = ConnectionState.Open; if (this.StateChange != null) { --- 398,402 ---- // Set connection state to Open ! this.state = ConnectionState.Open; if (this.StateChange != null) { *************** *** 407,416 **** // Add Info message event handler ! this.infoMessageHandler = new PgClientMessageEventHandler(OnInfoMessage); ! this.dbConnection.DB.InfoMessage += infoMessageHandler; // Add notification event handler ! this.notificationHandler = new PgClientNotificationEventHandler(OnNotification); ! this.dbConnection.DB.Notification += notificationHandler; } catch (PgClientException ex) --- 408,415 ---- // Add Info message event handler ! this.dbConnection.DB.InfoMessage = new InfoMessageCallback(this.OnInfoMessage); // Add notification event handler ! this.dbConnection.DB.Notification = new NotificationCallback(this.OnNotification); } catch (PgClientException ex) *************** *** 429,435 **** lock (this.dbConnection) { // Close DataReader ! if (this.dataReader != null && ! !this.dataReader.IsClosed) { this.dataReader.Close(); --- 428,439 ---- lock (this.dbConnection) { + // Remove info message callback + this.dbConnection.DB.InfoMessage = null; + + // Remove notification callback + this.dbConnection.DB.Notification = null; + // Close DataReader ! if (this.dataReader != null && !this.dataReader.IsClosed) { this.dataReader.Close(); *************** *** 446,461 **** } - // Remove info message event handler - if (this.infoMessageHandler != null) - { - this.dbConnection.DB.InfoMessage -= this.infoMessageHandler; - } - - // Remove notification event handler - if (this.notificationHandler != null) - { - this.dbConnection.DB.Notification -= this.notificationHandler; - } - // Remove SSL handlers this.ServerCertValidation = null; --- 450,453 ---- *************** *** 611,634 **** #region Event Handlers Methods ! private void OnInfoMessage(object sender, PgClientMessageEventArgs e) { ! if (InfoMessage != null) { ! InfoMessage(this, new PgInfoMessageEventArgs(e.Exception)); } } ! private void OnNotification(object sender, PgClientNotificationEventArgs e) { ! if (Notification != null) { ! Notification(this, ! new PgNotificationEventArgs( ! e.ProcessID, ! e.Condition, ! e.Aditional)); } } private bool OnServerCertificateValidation( X509Certificate certificate, --- 603,636 ---- #region Event Handlers Methods ! private void OnInfoMessage(PgClientException ex) { ! if (this.InfoMessage != null) { ! this.InfoMessage(this, new PgInfoMessageEventArgs(ex)); } } ! private void OnNotification(int processID, string condition, string aditional) { ! if (this.Notification != null) { ! this.Notification(this, new PgNotificationEventArgs(processID, condition, aditional)); } } + private void OnSslConnection() + { + PgDbClient db = this.dbConnection.DB; + + // Server certificate validation + db.SslClientStream.ServerCertValidationDelegate = new CertificateValidationCallback(OnServerCertificateValidation); + + // Client certificate selection + db.SslClientStream.ClientCertSelectionDelegate = new CertificateSelectionCallback(OnClientCertificateSelection); + + // Private key selection + db.SslClientStream.PrivateKeyCertSelectionDelegate = new PrivateKeySelectionCallback(OnPrivateKeySelection); + } + private bool OnServerCertificateValidation( X509Certificate certificate, *************** *** 673,688 **** } - private void OnSslConnection() - { - // Server certificate validation - dbConnection.DB.SslClientStream.ServerCertValidationDelegate = new CertificateValidationCallback(OnServerCertificateValidation); - - // Client certificate selection - dbConnection.DB.SslClientStream.ClientCertSelectionDelegate = new CertificateSelectionCallback(OnClientCertificateSelection); - - // Private key selection - dbConnection.DB.SslClientStream.PrivateKeyCertSelectionDelegate = new PrivateKeySelectionCallback(OnPrivateKeySelection); - } - #endregion } --- 675,678 ---- |
From: <ben...@id...> - 2004-05-22 12:47:10
|
Dear Open Source developer I am doing a research project on "Fun and Software Development" in which I kindly invite you to participate. You will find the online survey under http://fasd.ethz.ch/qsf/. The questionnaire consists of 53 questions and you will need about 15 minutes to complete it. With the FASD project (Fun and Software Development) we want to define the motivational significance of fun when software developers decide to engage in Open Source projects. What is special about our research project is that a similar survey is planned with software developers in commercial firms. This procedure allows the immediate comparison between the involved individuals and the conditions of production of these two development models. Thus we hope to obtain substantial new insights to the phenomenon of Open Source Development. With many thanks for your participation, Benno Luthiger PS: The results of the survey will be published under http://www.isu.unizh.ch/fuehrung/blprojects/FASD/. We have set up the mailing list fa...@we... for this study. Please see http://fasd.ethz.ch/qsf/mailinglist_en.html for registration to this mailing list. _______________________________________________________________________ Benno Luthiger Swiss Federal Institute of Technology Zurich 8092 Zurich Mail: benno.luthiger(at)id.ethz.ch _______________________________________________________________________ |
From: Carlos Guzm?n ?l. <car...@us...> - 2004-05-19 10:39:27
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient.UnitTests/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4785 Modified Files: PgBaseTest.cs Log Message: Add binary blob data to the test table data Index: PgBaseTest.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient.UnitTests/source/PgBaseTest.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** PgBaseTest.cs 9 Feb 2004 14:21:31 -0000 1.10 --- PgBaseTest.cs 19 May 2004 10:39:17 -0000 1.11 *************** *** 276,280 **** private void insertTestData() { ! string commandText = "insert into public.test_table values(@int4_field, @char_field, @varchar_field, @single_field, @double_field, @date_Field, @time_field, @timestamp_field)"; PgTransaction transaction = connection.BeginTransaction(); --- 276,280 ---- private void insertTestData() { ! string commandText = "insert into public.test_table values(@int4_field, @char_field, @varchar_field, @single_field, @double_field, @date_Field, @time_field, @timestamp_field, @blob_field)"; PgTransaction transaction = connection.BeginTransaction(); *************** *** 292,295 **** --- 292,296 ---- command.Parameters.Add("@time_field", PgDbType.Time); command.Parameters.Add("@timestamp_field", PgDbType.Timestamp); + command.Parameters.Add("@blob_field", PgDbType.Binary); for (int i = 0; i < 100; i++) *************** *** 303,306 **** --- 304,308 ---- command.Parameters["@time_field"].Value = DateTime.Now; command.Parameters["@timestamp_field"].Value = DateTime.Now; + command.Parameters["@blob_field"].Value = Encoding.Default.GetBytes("IRow " + i.ToString()); command.ExecuteNonQuery(); |
From: Carlos Guzm?n ?l. <car...@us...> - 2004-05-09 12:10:04
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30741 Modified Files: changelog.txt Log Message: Sync Mono.Security stuff wit Mono Beta 1 sources Index: changelog.txt =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/changelog.txt,v retrieving revision 1.116 retrieving revision 1.117 diff -C2 -d -r1.116 -r1.117 *** changelog.txt 6 May 2004 08:17:39 -0000 1.116 --- changelog.txt 9 May 2004 12:09:55 -0000 1.117 *************** *** 3,6 **** --- 3,10 ---- + 2004-05-09 Carlos Guzman Alvarez <car...@te...> + + * Symc Mono.Security stuff with mono beta 1 sources. + 2004-05-06 Carlos Guzman Alvarez <car...@te...> *************** *** 10,14 **** ( Disable the nagle algorithm on socket setup ) - 2004-05-03 Carlos Guzman Alvarez <car...@te...> --- 14,17 ---- |
From: Carlos Guzm?n ?l. <car...@us...> - 2004-05-09 12:07:27
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30429 Modified Files: TlsServerCertificate.cs Log Message: Sync Mono.Security stuff wit Mono Beta 1 sources Index: TlsServerCertificate.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Client/TlsServerCertificate.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TlsServerCertificate.cs 9 May 2004 12:05:48 -0000 1.11 --- TlsServerCertificate.cs 9 May 2004 12:07:16 -0000 1.12 *************** *** 228,232 **** try { ! result = !verify.Build (leaf); } catch (Exception) --- 228,232 ---- try { ! result = verify.Build (leaf); } catch (Exception) |
From: Carlos Guzm?n ?l. <car...@us...> - 2004-05-09 12:06:55
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509.Extensions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30263 Modified Files: AuthorityKeyIdentifierExtension.cs BasicConstraintsExtension.cs CertificatePoliciesExtension.cs CRLDistributionPointsExtension.cs ExtendedKeyUsageExtension.cs KeyAttributesExtension.cs KeyUsageExtension.cs NetscapeCertTypeExtension.cs PrivateKeyUsagePeriodExtension.cs SubjectAltNameExtension.cs SubjectKeyIdentifierExtension.cs Log Message: Sync Mono.Security stuff wit Mono Beta 1 sources Index: KeyAttributesExtension.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509.Extensions/KeyAttributesExtension.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** KeyAttributesExtension.cs 5 Mar 2004 23:19:07 -0000 1.1 --- KeyAttributesExtension.cs 9 May 2004 12:06:37 -0000 1.2 *************** *** 3,12 **** // // Author: ! // Sebastien Pouliot (spo...@mo...) // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) // using System; using System.Text; --- 3,14 ---- // // Author: ! // Sebastien Pouliot <seb...@xi...> // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) // using System; + using System.Globalization; using System.Text; *************** *** 41,45 **** // ( CONSTRAINED BY { -- at least one component shall be present -- }) ! internal class KeyAttributesExtension : X509Extension { private byte[] keyId; --- 43,47 ---- // ( CONSTRAINED BY { -- at least one component shall be present -- }) ! public class KeyAttributesExtension : X509Extension { private byte[] keyId; *************** *** 53,59 **** } ! public KeyAttributesExtension (ASN1 asn1) : base (asn1) {} ! public KeyAttributesExtension (X509Extension extension) : base (extension) {} protected override void Decode () --- 55,65 ---- } ! public KeyAttributesExtension (ASN1 asn1) : base (asn1) ! { ! } ! public KeyAttributesExtension (X509Extension extension) : base (extension) ! { ! } protected override void Decode () *************** *** 103,107 **** public byte[] KeyIdentifier { ! get { return keyId; } } --- 109,117 ---- public byte[] KeyIdentifier { ! get { ! if (keyId == null) ! return null; ! return (byte[]) keyId.Clone (); ! } } *************** *** 118,124 **** } ! public bool Support (KeyUsage usage) { ! int x = Convert.ToInt32 (usage); return ((x & kubits) == x); } --- 128,134 ---- } ! public bool Support (KeyUsages usage) { ! int x = Convert.ToInt32 (usage, CultureInfo.InvariantCulture); return ((x & kubits) == x); } *************** *** 131,135 **** int x = 0; while (x < keyId.Length) { ! sb.Append (keyId [x].ToString ("X2")); if (x % 2 == 1) sb.Append (" "); --- 141,145 ---- int x = 0; while (x < keyId.Length) { ! sb.Append (keyId [x].ToString ("X2", CultureInfo.InvariantCulture)); if (x % 2 == 1) sb.Append (" "); *************** *** 142,183 **** sb.Append ("Key Usage="); const string separator = " , "; ! if (Support (KeyUsage.digitalSignature)) sb.Append ("Digital Signature"); ! if (Support (KeyUsage.nonRepudiation)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Non-Repudiation"); } ! if (Support (KeyUsage.keyEncipherment)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Key Encipherment"); } ! if (Support (KeyUsage.dataEncipherment)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Data Encipherment"); } ! if (Support (KeyUsage.keyAgreement)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Key Agreement"); } ! if (Support (KeyUsage.keyCertSign)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Certificate Signing"); } ! if (Support (KeyUsage.cRLSign)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("CRL Signing"); } ! if (Support (KeyUsage.encipherOnly)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Encipher Only "); // ??? } ! if (Support (KeyUsage.decipherOnly)) { if (sb.Length > 0) sb.Append (separator); --- 152,193 ---- sb.Append ("Key Usage="); const string separator = " , "; ! if (Support (KeyUsages.digitalSignature)) sb.Append ("Digital Signature"); ! if (Support (KeyUsages.nonRepudiation)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Non-Repudiation"); } ! if (Support (KeyUsages.keyEncipherment)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Key Encipherment"); } ! if (Support (KeyUsages.dataEncipherment)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Data Encipherment"); } ! if (Support (KeyUsages.keyAgreement)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Key Agreement"); } ! if (Support (KeyUsages.keyCertSign)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Certificate Signing"); } ! if (Support (KeyUsages.cRLSign)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("CRL Signing"); } ! if (Support (KeyUsages.encipherOnly)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Encipher Only "); // ??? } ! if (Support (KeyUsages.decipherOnly)) { if (sb.Length > 0) sb.Append (separator); *************** *** 185,189 **** } sb.Append ("("); ! sb.Append (kubits.ToString ("X2")); sb.Append (")"); sb.Append (Environment.NewLine); --- 195,199 ---- } sb.Append ("("); ! sb.Append (kubits.ToString ("X2", CultureInfo.InvariantCulture)); sb.Append (")"); sb.Append (Environment.NewLine); *************** *** 192,201 **** if (notBefore != DateTime.MinValue) { sb.Append ("Not Before="); ! sb.Append (notBefore.ToString ()); sb.Append (Environment.NewLine); } if (notAfter != DateTime.MinValue) { sb.Append ("Not After="); ! sb.Append (notAfter.ToString ()); sb.Append (Environment.NewLine); } --- 202,211 ---- if (notBefore != DateTime.MinValue) { sb.Append ("Not Before="); ! sb.Append (notBefore.ToString (CultureInfo.CurrentUICulture)); sb.Append (Environment.NewLine); } if (notAfter != DateTime.MinValue) { sb.Append ("Not After="); ! sb.Append (notAfter.ToString (CultureInfo.CurrentUICulture)); sb.Append (Environment.NewLine); } Index: NetscapeCertTypeExtension.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509.Extensions/NetscapeCertTypeExtension.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NetscapeCertTypeExtension.cs 5 Mar 2004 23:19:07 -0000 1.1 --- NetscapeCertTypeExtension.cs 9 May 2004 12:06:37 -0000 1.2 *************** *** 9,12 **** --- 9,13 ---- using System; + using System.Globalization; using System.Text; *************** *** 24,28 **** // http://www.alvestrand.no/objectid/2.16.840.1.113730.1.1.html ! internal class NetscapeCertTypeExtension : X509Extension { /* --- 25,29 ---- // http://www.alvestrand.no/objectid/2.16.840.1.113730.1.1.html ! public class NetscapeCertTypeExtension : X509Extension { /* *************** *** 39,49 **** // note: because nothing is simple in ASN.1 bits are reversed [Flags] ! public enum CertType { SslClient = 0x80, SslServer = 0x40, Smime = 0x20, ObjectSigning = 0x10, ! SslCa = 0x04, ! SmimeCa = 0x02, ObjectSigningCA = 0x01 } --- 40,50 ---- // note: because nothing is simple in ASN.1 bits are reversed [Flags] ! public enum CertTypes { SslClient = 0x80, SslServer = 0x40, Smime = 0x20, ObjectSigning = 0x10, ! SslCA = 0x04, ! SmimeCA = 0x02, ObjectSigningCA = 0x01 } *************** *** 56,62 **** } ! public NetscapeCertTypeExtension (ASN1 asn1) : base (asn1) {} ! public NetscapeCertTypeExtension (X509Extension extension) : base (extension) {} protected override void Decode () --- 57,67 ---- } ! public NetscapeCertTypeExtension (ASN1 asn1) : base (asn1) ! { ! } ! public NetscapeCertTypeExtension (X509Extension extension) : base (extension) ! { ! } protected override void Decode () *************** *** 79,85 **** }*/ ! public bool Support (CertType usage) { ! int x = Convert.ToInt32 (usage); return ((x & ctbits) == x); } --- 84,90 ---- }*/ ! public bool Support (CertTypes usage) { ! int x = Convert.ToInt32 (usage, CultureInfo.InvariantCulture); return ((x & ctbits) == x); } *************** *** 89,120 **** const string separator = " , "; StringBuilder sb = new StringBuilder (); ! if (Support (CertType.SslClient)) sb.Append ("SSL Client Authentication"); ! if (Support (CertType.SslServer)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("SSL Server Authentication"); } ! if (Support (CertType.Smime)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("SMIME"); } ! if (Support (CertType.ObjectSigning)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Object Signing"); } ! if (Support (CertType.SslCa)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("SSL CA"); } ! if (Support (CertType.SmimeCa)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("SMIME CA"); } ! if (Support (CertType.ObjectSigningCA)) { if (sb.Length > 0) sb.Append (separator); --- 94,125 ---- const string separator = " , "; StringBuilder sb = new StringBuilder (); ! if (Support (CertTypes.SslClient)) sb.Append ("SSL Client Authentication"); ! if (Support (CertTypes.SslServer)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("SSL Server Authentication"); } ! if (Support (CertTypes.Smime)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("SMIME"); } ! if (Support (CertTypes.ObjectSigning)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Object Signing"); } ! if (Support (CertTypes.SslCA)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("SSL CA"); } ! if (Support (CertTypes.SmimeCA)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("SMIME CA"); } ! if (Support (CertTypes.ObjectSigningCA)) { if (sb.Length > 0) sb.Append (separator); *************** *** 122,126 **** } sb.Append ("("); ! sb.Append (ctbits.ToString ("X2")); sb.Append (")"); sb.Append (Environment.NewLine); --- 127,131 ---- } sb.Append ("("); ! sb.Append (ctbits.ToString ("X2", CultureInfo.InvariantCulture)); sb.Append (")"); sb.Append (Environment.NewLine); Index: ExtendedKeyUsageExtension.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509.Extensions/ExtendedKeyUsageExtension.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ExtendedKeyUsageExtension.cs 5 Mar 2004 23:19:07 -0000 1.1 --- ExtendedKeyUsageExtension.cs 9 May 2004 12:06:37 -0000 1.2 *************** *** 3,9 **** // // Author: ! // Sebastien Pouliot (spo...@mo...) // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) // --- 3,10 ---- // // Author: ! // Sebastien Pouliot <seb...@xi...> // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) // *************** *** 25,29 **** */ ! internal class ExtendedKeyUsageExtension : X509Extension { private ArrayList keyPurpose; --- 26,30 ---- */ ! public class ExtendedKeyUsageExtension : X509Extension { private ArrayList keyPurpose; *************** *** 35,41 **** } ! public ExtendedKeyUsageExtension (ASN1 asn1) : base (asn1) {} ! public ExtendedKeyUsageExtension (X509Extension extension) : base (extension) {} protected override void Decode () --- 36,46 ---- } ! public ExtendedKeyUsageExtension (ASN1 asn1) : base (asn1) ! { ! } ! public ExtendedKeyUsageExtension (X509Extension extension) : base (extension) ! { ! } protected override void Decode () *************** *** 47,51 **** // for every policy OID for (int i=0; i < sequence.Count; i++) ! keyPurpose.Add (ASN1Convert.ToOID (sequence [i])); } --- 52,56 ---- // for every policy OID for (int i=0; i < sequence.Count; i++) ! keyPurpose.Add (ASN1Convert.ToOid (sequence [i])); } *************** *** 55,59 **** extnValue = new ASN1 (0x30); foreach (string oid in keyPurpose) { ! extnValue.Add (ASN1Convert.FromOID (oid)); } } --- 60,64 ---- extnValue = new ASN1 (0x30); foreach (string oid in keyPurpose) { ! extnValue.Add (ASN1Convert.FromOid (oid)); } } *************** *** 79,93 **** foreach (string s in keyPurpose) { switch (s) { case "1.3.6.1.5.5.7.3.3": sb.Append ("Code Signing"); break; default: sb.Append ("unknown"); break; } ! sb.Append (" ("); ! sb.Append (s); ! sb.Append (")"); ! sb.Append (Environment.NewLine); } return sb.ToString (); --- 84,110 ---- foreach (string s in keyPurpose) { switch (s) { + case "1.3.6.1.5.5.7.3.1": + sb.Append ("Server Authentication"); + break; + case "1.3.6.1.5.5.7.3.2": + sb.Append ("Client Authentication"); + break; case "1.3.6.1.5.5.7.3.3": sb.Append ("Code Signing"); break; + case "1.3.6.1.5.5.7.3.4": + sb.Append ("Email Protection"); + break; + case "1.3.6.1.5.5.7.3.8": + sb.Append ("Time Stamping"); + break; + case "1.3.6.1.5.5.7.3.9": + sb.Append ("OCSP Signing"); + break; default: sb.Append ("unknown"); break; } ! sb.AppendFormat (" ({0}){1}", s, Environment.NewLine); } return sb.ToString (); Index: SubjectAltNameExtension.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509.Extensions/SubjectAltNameExtension.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SubjectAltNameExtension.cs 5 Mar 2004 23:19:07 -0000 1.1 --- SubjectAltNameExtension.cs 9 May 2004 12:06:37 -0000 1.2 *************** *** 3,9 **** // // Author: ! // Sebastien Pouliot (spo...@mo...) // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) // --- 3,10 ---- // // Author: ! // Sebastien Pouliot <seb...@xi...> // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) // *************** *** 49,53 **** // TODO - incomplete (only rfc822Name, dNSName are supported) ! internal class SubjectAltNameExtension : X509Extension { private ArrayList rfc822Name; --- 50,54 ---- // TODO - incomplete (only rfc822Name, dNSName are supported) ! public class SubjectAltNameExtension : X509Extension { private ArrayList rfc822Name; *************** *** 98,105 **** public string[] RFC822 { get { ! string[] names = new string [rfc822Name.Count]; ! for (int i=0; i < rfc822Name.Count; i++) ! names [i] = (string) rfc822Name [i]; ! return names; } } --- 99,105 ---- public string[] RFC822 { get { ! if (rfc822Name == null) ! return new string [0]; ! return (string[]) rfc822Name.ToArray (typeof(string)); } } Index: CertificatePoliciesExtension.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509.Extensions/CertificatePoliciesExtension.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CertificatePoliciesExtension.cs 5 Mar 2004 23:19:07 -0000 1.1 --- CertificatePoliciesExtension.cs 9 May 2004 12:06:37 -0000 1.2 *************** *** 69,73 **** // note: partial implementation (only policyIdentifier OID are supported) ! internal class CertificatePoliciesExtension : X509Extension { private Hashtable policies; --- 69,73 ---- // note: partial implementation (only policyIdentifier OID are supported) ! public class CertificatePoliciesExtension : X509Extension { private Hashtable policies; *************** *** 79,85 **** } ! public CertificatePoliciesExtension (ASN1 asn1) : base (asn1) {} ! public CertificatePoliciesExtension (X509Extension extension) : base (extension) {} protected override void Decode () --- 79,89 ---- } ! public CertificatePoliciesExtension (ASN1 asn1) : base (asn1) ! { ! } ! public CertificatePoliciesExtension (X509Extension extension) : base (extension) ! { ! } protected override void Decode () *************** *** 91,95 **** // for every policy OID for (int i=0; i < sequence.Count; i++) { ! policies.Add (ASN1Convert.ToOID (sequence [i][0]), null); } } --- 95,99 ---- // for every policy OID for (int i=0; i < sequence.Count; i++) { ! policies.Add (ASN1Convert.ToOid (sequence [i][0]), null); } } Index: AuthorityKeyIdentifierExtension.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509.Extensions/AuthorityKeyIdentifierExtension.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AuthorityKeyIdentifierExtension.cs 5 Mar 2004 23:19:07 -0000 1.1 --- AuthorityKeyIdentifierExtension.cs 9 May 2004 12:06:36 -0000 1.2 *************** *** 9,12 **** --- 9,13 ---- using System; + using System.Globalization; using System.Text; *************** *** 27,32 **** */ ! internal class AuthorityKeyIdentifierExtension : X509Extension ! { private byte[] aki; --- 28,32 ---- */ ! public class AuthorityKeyIdentifierExtension : X509Extension { private byte[] aki; *************** *** 37,43 **** } ! public AuthorityKeyIdentifierExtension (ASN1 asn1) : base (asn1) {} ! public AuthorityKeyIdentifierExtension (X509Extension extension) : base (extension) {} protected override void Decode () --- 37,47 ---- } ! public AuthorityKeyIdentifierExtension (ASN1 asn1) : base (asn1) ! { ! } ! public AuthorityKeyIdentifierExtension (X509Extension extension) : base (extension) ! { ! } protected override void Decode () *************** *** 72,76 **** sb.Append ("KeyID="); while (x < aki.Length) { ! sb.Append (aki [x].ToString ("X2")); if (x % 2 == 1) sb.Append (" "); --- 76,80 ---- sb.Append ("KeyID="); while (x < aki.Length) { ! sb.Append (aki [x].ToString ("X2", CultureInfo.InvariantCulture)); if (x % 2 == 1) sb.Append (" "); Index: CRLDistributionPointsExtension.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509.Extensions/CRLDistributionPointsExtension.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CRLDistributionPointsExtension.cs 8 Mar 2004 12:45:57 -0000 1.2 --- CRLDistributionPointsExtension.cs 9 May 2004 12:06:37 -0000 1.3 *************** *** 51,55 **** */ ! internal class CRLDistributionPointsExtension : X509Extension { internal class DP { --- 51,55 ---- */ ! public class CRLDistributionPointsExtension : X509Extension { internal class DP { *************** *** 57,64 **** public ReasonFlags Reasons; public string CRLIssuer; } [Flags] ! internal enum ReasonFlags { Unused = 0, KeyCompromise = 1, --- 57,71 ---- public ReasonFlags Reasons; public string CRLIssuer; + + public DP (string dp, ReasonFlags reasons, string issuer) + { + DistributionPoint = dp; + Reasons = reasons; + CRLIssuer = issuer; + } } [Flags] ! public enum ReasonFlags { Unused = 0, KeyCompromise = 1, Index: PrivateKeyUsagePeriodExtension.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509.Extensions/PrivateKeyUsagePeriodExtension.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PrivateKeyUsagePeriodExtension.cs 5 Mar 2004 23:19:07 -0000 1.1 --- PrivateKeyUsagePeriodExtension.cs 9 May 2004 12:06:37 -0000 1.2 *************** *** 9,12 **** --- 9,13 ---- using System; + using System.Globalization; using System.Text; *************** *** 24,28 **** * } */ ! internal class PrivateKeyUsagePeriodExtension : X509Extension { private DateTime notBefore; --- 25,29 ---- * } */ ! public class PrivateKeyUsagePeriodExtension : X509Extension { private DateTime notBefore; *************** *** 34,40 **** } ! public PrivateKeyUsagePeriodExtension (ASN1 asn1) : base (asn1) {} ! public PrivateKeyUsagePeriodExtension (X509Extension extension) : base (extension) {} protected override void Decode () --- 35,45 ---- } ! public PrivateKeyUsagePeriodExtension (ASN1 asn1) : base (asn1) ! { ! } ! public PrivateKeyUsagePeriodExtension (X509Extension extension) : base (extension) ! { ! } protected override void Decode () *************** *** 66,75 **** if (notBefore != DateTime.MinValue) { sb.Append ("Not Before: "); ! sb.Append (notBefore.ToString ()); sb.Append (Environment.NewLine); } if (notAfter != DateTime.MinValue) { sb.Append ("Not After: "); ! sb.Append (notAfter.ToString ()); sb.Append (Environment.NewLine); } --- 71,80 ---- if (notBefore != DateTime.MinValue) { sb.Append ("Not Before: "); ! sb.Append (notBefore.ToString (CultureInfo.CurrentUICulture)); sb.Append (Environment.NewLine); } if (notAfter != DateTime.MinValue) { sb.Append ("Not After: "); ! sb.Append (notAfter.ToString (CultureInfo.CurrentUICulture)); sb.Append (Environment.NewLine); } Index: SubjectKeyIdentifierExtension.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509.Extensions/SubjectKeyIdentifierExtension.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SubjectKeyIdentifierExtension.cs 5 Mar 2004 23:19:07 -0000 1.1 --- SubjectKeyIdentifierExtension.cs 9 May 2004 12:06:37 -0000 1.2 *************** *** 9,12 **** --- 9,13 ---- using System; + using System.Globalization; using System.Text; *************** *** 24,28 **** */ ! internal class SubjectKeyIdentifierExtension : X509Extension { private byte[] ski; --- 25,34 ---- */ ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class SubjectKeyIdentifierExtension : X509Extension { private byte[] ski; *************** *** 33,39 **** } ! public SubjectKeyIdentifierExtension (ASN1 asn1) : base (asn1) {} ! public SubjectKeyIdentifierExtension (X509Extension extension) : base (extension) {} protected override void Decode () --- 39,49 ---- } ! public SubjectKeyIdentifierExtension (ASN1 asn1) : base (asn1) ! { ! } ! public SubjectKeyIdentifierExtension (X509Extension extension) : base (extension) ! { ! } protected override void Decode () *************** *** 50,54 **** public byte[] Identifier { ! get { return (byte[]) ski.Clone (); } } --- 60,68 ---- public byte[] Identifier { ! get { ! if (ski == null) ! return null; ! return (byte[]) ski.Clone (); ! } } *************** *** 61,65 **** int x = 0; while (x < ski.Length) { ! sb.Append (ski [x].ToString ("X2")); if (x % 2 == 1) sb.Append (" "); --- 75,79 ---- int x = 0; while (x < ski.Length) { ! sb.Append (ski [x].ToString ("X2", CultureInfo.InvariantCulture)); if (x % 2 == 1) sb.Append (" "); Index: BasicConstraintsExtension.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509.Extensions/BasicConstraintsExtension.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BasicConstraintsExtension.cs 5 Mar 2004 23:19:07 -0000 1.1 --- BasicConstraintsExtension.cs 9 May 2004 12:06:37 -0000 1.2 *************** *** 3,12 **** // // Author: ! // Sebastien Pouliot (spo...@mo...) // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) // using System; using System.Text; --- 3,14 ---- // // Author: ! // Sebastien Pouliot <seb...@xi...> // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) // using System; + using System.Globalization; using System.Text; *************** *** 27,31 **** * } */ ! internal class BasicConstraintsExtension : X509Extension { private bool cA; --- 29,38 ---- * } */ ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class BasicConstraintsExtension : X509Extension { private bool cA; *************** *** 95,99 **** sb.Append ("None"); else ! sb.Append (pathLenConstraint.ToString ()); sb.Append (Environment.NewLine); return sb.ToString (); --- 102,106 ---- sb.Append ("None"); else ! sb.Append (pathLenConstraint.ToString (CultureInfo.InvariantCulture)); sb.Append (Environment.NewLine); return sb.ToString (); Index: KeyUsageExtension.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509.Extensions/KeyUsageExtension.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** KeyUsageExtension.cs 5 Mar 2004 23:19:07 -0000 1.1 --- KeyUsageExtension.cs 9 May 2004 12:06:37 -0000 1.2 *************** *** 3,12 **** // // Author: ! // Sebastien Pouliot (spo...@mo...) // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) // using System; using System.Text; --- 3,14 ---- // // Author: ! // Sebastien Pouliot <seb...@xi...> // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) // using System; + using System.Globalization; using System.Text; *************** *** 33,37 **** // note: because nothing is simple in ASN.1 bits are reversed [Flags] ! internal enum KeyUsage { digitalSignature = 0x80, nonRepudiation = 0x40, --- 35,44 ---- // note: because nothing is simple in ASN.1 bits are reversed [Flags] ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! enum KeyUsages { digitalSignature = 0x80, nonRepudiation = 0x40, *************** *** 46,50 **** } ! internal class KeyUsageExtension : X509Extension { private int kubits; --- 53,62 ---- } ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class KeyUsageExtension : X509Extension { private int kubits; *************** *** 68,74 **** } ! public bool Support (KeyUsage usage) { ! int x = Convert.ToInt32 (usage); return ((x & kubits) == x); } --- 80,86 ---- } ! public bool Support (KeyUsages usage) { ! int x = Convert.ToInt32 (usage, CultureInfo.InvariantCulture); return ((x & kubits) == x); } *************** *** 78,119 **** const string separator = " , "; StringBuilder sb = new StringBuilder (); ! if (Support (KeyUsage.digitalSignature)) sb.Append ("Digital Signature"); ! if (Support (KeyUsage.nonRepudiation)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Non-Repudiation"); } ! if (Support (KeyUsage.keyEncipherment)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Key Encipherment"); } ! if (Support (KeyUsage.dataEncipherment)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Data Encipherment"); } ! if (Support (KeyUsage.keyAgreement)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Key Agreement"); } ! if (Support (KeyUsage.keyCertSign)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Certificate Signing"); } ! if (Support (KeyUsage.cRLSign)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("CRL Signing"); } ! if (Support (KeyUsage.encipherOnly)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Encipher Only "); // ??? } ! if (Support (KeyUsage.decipherOnly)) { if (sb.Length > 0) sb.Append (separator); --- 90,131 ---- const string separator = " , "; StringBuilder sb = new StringBuilder (); ! if (Support (KeyUsages.digitalSignature)) sb.Append ("Digital Signature"); ! if (Support (KeyUsages.nonRepudiation)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Non-Repudiation"); } ! if (Support (KeyUsages.keyEncipherment)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Key Encipherment"); } ! if (Support (KeyUsages.dataEncipherment)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Data Encipherment"); } ! if (Support (KeyUsages.keyAgreement)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Key Agreement"); } ! if (Support (KeyUsages.keyCertSign)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Certificate Signing"); } ! if (Support (KeyUsages.cRLSign)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("CRL Signing"); } ! if (Support (KeyUsages.encipherOnly)) { if (sb.Length > 0) sb.Append (separator); sb.Append ("Encipher Only "); // ??? } ! if (Support (KeyUsages.decipherOnly)) { if (sb.Length > 0) sb.Append (separator); *************** *** 121,125 **** } sb.Append ("("); ! sb.Append (kubits.ToString ("X2")); sb.Append (")"); sb.Append (Environment.NewLine); --- 133,137 ---- } sb.Append ("("); ! sb.Append (kubits.ToString ("X2", CultureInfo.InvariantCulture)); sb.Append (")"); sb.Append (Environment.NewLine); |
From: Carlos Guzm?n ?l. <car...@us...> - 2004-05-09 12:06:30
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30177 Modified Files: ITrustAnchors.cs PKCS12.cs TrustAnchors.cs X501Name.cs X509Builder.cs X509Certificate.cs X509CertificateBuilder.cs X509CertificateCollection.cs X509Chain.cs X509ChainStatusFlags.cs X509CRL.cs X509Extension.cs X509Extensions.cs X509Store.cs X509StoreManager.cs X509Stores.cs X520Attributes.cs Log Message: Sync Mono.Security stuff wit Mono Beta 1 sources Index: X509Extension.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/X509Extension.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** X509Extension.cs 10 Feb 2004 09:46:25 -0000 1.1 --- X509Extension.cs 9 May 2004 12:06:15 -0000 1.2 *************** *** 3,12 **** // // Author: ! // Sebastien Pouliot (spo...@mo...) // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) // using System; using System.Text; --- 3,14 ---- // // Author: ! // Sebastien Pouliot <seb...@xi...> // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) // using System; + using System.Globalization; using System.Text; *************** *** 21,25 **** * } */ ! internal class X509Extension { protected string extnOid; --- 23,32 ---- * } */ ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class X509Extension { protected string extnOid; *************** *** 38,42 **** if (asn1[0].Tag != 0x06) throw new ArgumentException ("Invalid X.509 extension"); ! extnOid = ASN1Convert.ToOID (asn1 [0]); extnCritical = ((asn1[1].Tag == 0x01) && (asn1[1].Value[0] == 0xFF)); extnValue = asn1 [asn1.Count - 1]; // last element --- 45,49 ---- if (asn1[0].Tag != 0x06) throw new ArgumentException ("Invalid X.509 extension"); ! extnOid = ASN1Convert.ToOid (asn1 [0]); extnCritical = ((asn1[1].Tag == 0x01) && (asn1[1].Value[0] == 0xFF)); extnValue = asn1 [asn1.Count - 1]; // last element *************** *** 50,54 **** if ((extension.Value.Tag != 0x04) || (extension.Value.Count != 0)) throw new ArgumentException ("Invalid extension"); ! extnOid = extension.OID; extnCritical = extension.Critical; extnValue = extension.Value; --- 57,61 ---- if ((extension.Value.Tag != 0x04) || (extension.Value.Count != 0)) throw new ArgumentException ("Invalid extension"); ! extnOid = extension.Oid; extnCritical = extension.Critical; extnValue = extension.Value; *************** *** 56,67 **** } ! protected virtual void Decode () {} ! protected virtual void Encode () {} public ASN1 ASN1 { get { ASN1 extension = new ASN1 (0x30); ! extension.Add (ASN1Convert.FromOID (extnOid)); if (extnCritical) extension.Add (new ASN1 (0x01, new byte [1] { 0x01 })); --- 63,78 ---- } ! protected virtual void Decode () ! { ! } ! protected virtual void Encode () ! { ! } public ASN1 ASN1 { get { ASN1 extension = new ASN1 (0x30); ! extension.Add (ASN1Convert.FromOid (extnOid)); if (extnCritical) extension.Add (new ASN1 (0x01, new byte [1] { 0x01 })); *************** *** 73,77 **** } ! public string OID { get { return extnOid; } } --- 84,88 ---- } ! public string Oid { get { return extnOid; } } *************** *** 90,93 **** --- 101,127 ---- } + public override bool Equals (object obj) + { + if (obj == null) + return false; + + X509Extension ex = (obj as X509Extension); + if (ex == null) + return false; + + if (extnCritical != ex.extnCritical) + return false; + if (extnOid != ex.extnOid) + return false; + if (extnValue.Length != ex.extnValue.Length) + return false; + + for (int i=0; i < extnValue.Length; i++) { + if (extnValue [i] != ex.extnValue [i]) + return false; + } + return true; + } + public byte[] GetBytes () { *************** *** 95,98 **** --- 129,138 ---- } + public override int GetHashCode () + { + // OID should be unique in a collection of extensions + return extnOid.GetHashCode (); + } + private void WriteLine (StringBuilder sb, int n, int pos) { *************** *** 102,106 **** for (int j=0; j < 8; j++) { if (j < n) { ! sb.Append (value [p++].ToString ("X2")); sb.Append (" "); } --- 142,146 ---- for (int j=0; j < 8; j++) { if (j < n) { ! sb.Append (value [p++].ToString ("X2", CultureInfo.InvariantCulture)); sb.Append (" "); } Index: ITrustAnchors.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/ITrustAnchors.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ITrustAnchors.cs 10 Feb 2004 09:46:25 -0000 1.1 --- ITrustAnchors.cs 9 May 2004 12:06:15 -0000 1.2 *************** *** 12,16 **** namespace Mono.Security.X509 { ! internal interface ITrustAnchors { X509CertificateCollection Anchors { get; } --- 12,16 ---- namespace Mono.Security.X509 { ! public interface ITrustAnchors { X509CertificateCollection Anchors { get; } Index: X509Stores.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/X509Stores.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** X509Stores.cs 5 Mar 2004 23:18:17 -0000 1.1 --- X509Stores.cs 9 May 2004 12:06:15 -0000 1.2 *************** *** 16,20 **** namespace Mono.Security.X509 { ! internal class X509Stores { private string _storePath; --- 16,25 ---- namespace Mono.Security.X509 { ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class X509Stores { private string _storePath; *************** *** 106,110 **** // names ! internal class Names { // do not translate --- 111,115 ---- // names ! public class Names { // do not translate Index: X509Certificate.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/X509Certificate.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** X509Certificate.cs 5 Mar 2004 23:18:17 -0000 1.2 --- X509Certificate.cs 9 May 2004 12:06:15 -0000 1.3 *************** *** 3,9 **** // // Author: ! // Sebastien Pouliot (spo...@mo...) // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) // --- 3,10 ---- // // Author: ! // Sebastien Pouliot <seb...@xi...> // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) // *************** *** 21,25 **** // http://www.itu.int/ITU-T/studygroups/com17/languages/ ! internal class X509Certificate { private ASN1 decoder; --- 22,31 ---- // http://www.itu.int/ITU-T/studygroups/com17/languages/ ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class X509Certificate { private ASN1 decoder; *************** *** 36,39 **** --- 42,46 ---- private string m_signaturealgo; private byte[] m_signaturealgoparams; + private byte[] certhash; // from http://www.ietf.org/rfc/rfc2459.txt *************** *** 63,67 **** private byte[] issuerUniqueID; private byte[] subjectUniqueID; ! private X509Extensions extensions; // that's were the real job is! --- 70,74 ---- private byte[] issuerUniqueID; private byte[] subjectUniqueID; ! private X509ExtensionCollection extensions; // that's were the real job is! *************** *** 116,120 **** ASN1 algorithm = subjectPublicKeyInfo.Element (0, 0x30); ASN1 algo = algorithm.Element (0, 0x06); ! m_keyalgo = ASN1Convert.ToOID (algo); // parameters ANY DEFINED BY algorithm OPTIONAL // so we dont ask for a specific (Element) type and return DER --- 123,127 ---- ASN1 algorithm = subjectPublicKeyInfo.Element (0, 0x30); ASN1 algo = algorithm.Element (0, 0x06); ! m_keyalgo = ASN1Convert.ToOid (algo); // parameters ANY DEFINED BY algorithm OPTIONAL // so we dont ask for a specific (Element) type and return DER *************** *** 127,131 **** int n = subjectPublicKey.Length - 1; m_publickey = new byte [n]; ! Array.Copy (subjectPublicKey.Value, 1, m_publickey, 0, n); // signature processing --- 134,138 ---- int n = subjectPublicKey.Length - 1; m_publickey = new byte [n]; ! Buffer.BlockCopy (subjectPublicKey.Value, 1, m_publickey, 0, n); // signature processing *************** *** 133,141 **** // first byte contains unused bits in first byte signature = new byte [bitstring.Length - 1]; ! Array.Copy (bitstring, 1, signature, 0, signature.Length); algorithm = decoder [1]; algo = algorithm.Element (0, 0x06); ! m_signaturealgo = ASN1Convert.ToOID (algo); parameters = algorithm [1]; if (parameters != null) --- 140,148 ---- // first byte contains unused bits in first byte signature = new byte [bitstring.Length - 1]; ! Buffer.BlockCopy (bitstring, 1, signature, 0, signature.Length); algorithm = decoder [1]; algo = algorithm.Element (0, 0x06); ! m_signaturealgo = ASN1Convert.ToOid (algo); parameters = algorithm [1]; if (parameters != null) *************** *** 161,167 **** ASN1 extns = tbsCertificate.Element (tbs, 0xA3); if ((extns != null) && (extns.Count == 1)) ! extensions = new X509Extensions (extns [0]); else ! extensions = new X509Extensions (null); // keep a copy of the original data --- 168,174 ---- ASN1 extns = tbsCertificate.Element (tbs, 0xA3); if ((extns != null) && (extns.Count == 1)) ! extensions = new X509ExtensionCollection (extns [0]); else ! extensions = new X509ExtensionCollection (null); // keep a copy of the original data *************** *** 188,192 **** int length = integer.Length - 1; byte[] uinteger = new byte [length]; ! Array.Copy (integer, 1, uinteger, 0, length); return uinteger; } --- 195,199 ---- int length = integer.Length - 1; byte[] uinteger = new byte [length]; ! Buffer.BlockCopy (integer, 1, uinteger, 0, length); return uinteger; } *************** *** 224,228 **** } ! public X509Extensions Extensions { get { return extensions; } } --- 231,235 ---- } ! public X509ExtensionCollection Extensions { get { return extensions; } } *************** *** 230,257 **** public byte[] Hash { get { ! HashAlgorithm hash = null; ! switch (m_signaturealgo) { ! case "1.2.840.113549.1.1.2": // MD2 with RSA encryption ! // maybe someone installed MD2 ? ! hash = HashAlgorithm.Create ("MD2"); ! break; ! case "1.2.840.113549.1.1.4": // MD5 with RSA encryption ! hash = MD5.Create (); ! break; ! case "1.2.840.113549.1.1.5": // SHA-1 with RSA Encryption ! case "1.3.14.3.2.29": // SHA1 with RSA signature ! case "1.2.840.10040.4.3": // SHA1-1 with DSA ! hash = SHA1.Create (); ! break; ! default: return null; - } - try { byte[] toBeSigned = decoder [0].GetBytes (); ! return hash.ComputeHash (toBeSigned, 0, toBeSigned.Length); ! } ! catch { ! return null; } } } --- 237,264 ---- public byte[] Hash { get { ! if (certhash == null) { ! HashAlgorithm hash = null; ! switch (m_signaturealgo) { ! case "1.2.840.113549.1.1.2": // MD2 with RSA encryption ! // maybe someone installed MD2 ? ! hash = HashAlgorithm.Create ("MD2"); ! break; ! case "1.2.840.113549.1.1.4": // MD5 with RSA encryption ! hash = MD5.Create (); ! break; ! case "1.2.840.113549.1.1.5": // SHA-1 with RSA Encryption ! case "1.3.14.3.2.29": // SHA1 with RSA signature ! case "1.2.840.10040.4.3": // SHA1-1 with DSA ! hash = SHA1.Create (); ! break; ! default: ! return null; ! } ! if ((decoder == null) || (decoder.Count < 1)) return null; byte[] toBeSigned = decoder [0].GetBytes (); ! certhash = hash.ComputeHash (toBeSigned, 0, toBeSigned.Length); } + return (byte[]) certhash.Clone (); } } *************** *** 266,274 **** public virtual byte[] KeyAlgorithmParameters { ! get { return m_keyalgoparams; } } public virtual byte[] PublicKey { ! get { return m_publickey; } } --- 273,289 ---- public virtual byte[] KeyAlgorithmParameters { ! get { ! if (m_keyalgoparams == null) ! return null; ! return (byte[]) m_keyalgoparams.Clone (); ! } } public virtual byte[] PublicKey { ! get { ! if (m_publickey == null) ! return null; ! return (byte[]) m_publickey.Clone (); ! } } *************** *** 304,312 **** public virtual byte[] SerialNumber { ! get { return serialnumber; } } public virtual byte[] Signature { get { switch (m_signaturealgo) { case "1.2.840.113549.1.1.2": // MD2 with RSA encryption --- 319,334 ---- public virtual byte[] SerialNumber { ! get { ! if (serialnumber == null) ! return null; ! return (byte[]) serialnumber.Clone (); ! } } public virtual byte[] Signature { get { + if (signature == null) + return null; + switch (m_signaturealgo) { case "1.2.840.113549.1.1.2": // MD2 with RSA encryption *************** *** 314,318 **** case "1.2.840.113549.1.1.5": // SHA-1 with RSA Encryption case "1.3.14.3.2.29": // SHA1 with RSA signature ! return signature; case "1.2.840.10040.4.3": // SHA-1 with DSA ASN1 sign = new ASN1 (signature); --- 336,341 ---- case "1.2.840.113549.1.1.5": // SHA-1 with RSA Encryption case "1.3.14.3.2.29": // SHA1 with RSA signature ! return (byte[]) signature.Clone (); ! case "1.2.840.10040.4.3": // SHA-1 with DSA ASN1 sign = new ASN1 (signature); *************** *** 323,329 **** byte[] part2 = sign [1].Value; byte[] sig = new byte [40]; ! Array.Copy (part1, 0, sig, (20 - part1.Length), part1.Length); ! Array.Copy (part2, 0, sig, (40 - part2.Length), part2.Length); return sig; default: throw new CryptographicException ("Unsupported hash algorithm: " + m_signaturealgo); --- 346,353 ---- byte[] part2 = sign [1].Value; byte[] sig = new byte [40]; ! Buffer.BlockCopy (part1, 0, sig, (20 - part1.Length), part1.Length); ! Buffer.BlockCopy (part2, 0, sig, (40 - part2.Length), part2.Length); return sig; + default: throw new CryptographicException ("Unsupported hash algorithm: " + m_signaturealgo); *************** *** 337,341 **** public virtual byte[] SignatureAlgorithmParameters { ! get { return m_signaturealgoparams; } } --- 361,369 ---- public virtual byte[] SignatureAlgorithmParameters { ! get { ! if (m_signaturealgoparams == null) ! return m_signaturealgoparams; ! return (byte[]) m_signaturealgoparams.Clone (); ! } } *************** *** 360,376 **** } ! public bool WasCurrent (DateTime date) ! { ! return ((date > ValidFrom) && (date <= ValidUntil)); ! } ! ! private byte[] GetHash (string hashName) { ! byte[] toBeSigned = decoder [0].GetBytes (); ! HashAlgorithm ha = HashAlgorithm.Create (hashName); ! return ha.ComputeHash (toBeSigned); } ! public bool VerifySignature (DSA dsa) { // signatureOID is check by both this.Hash and this.Signature --- 388,397 ---- } ! public bool WasCurrent (DateTime instant) { ! return ((instant > ValidFrom) && (instant <= ValidUntil)); } ! internal bool VerifySignature (DSA dsa) { // signatureOID is check by both this.Hash and this.Signature *************** *** 407,410 **** --- 428,434 ---- public bool VerifySignature (AsymmetricAlgorithm aa) { + if (aa == null) + throw new ArgumentNullException ("aa"); + if (aa is RSA) return VerifySignature (aa as RSA); Index: X509Chain.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/X509Chain.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** X509Chain.cs 5 Mar 2004 23:18:17 -0000 1.2 --- X509Chain.cs 9 May 2004 12:06:15 -0000 1.3 *************** *** 14,18 **** --- 14,23 ---- using System; + using System.Security; + using System.Security.Permissions; + + #if !INSIDE_CORLIB using System.Net; + #endif using Mono.Security.X509.Extensions; *************** *** 20,24 **** namespace Mono.Security.X509 { ! internal class X509Chain { private X509CertificateCollection roots; --- 25,34 ---- namespace Mono.Security.X509 { ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class X509Chain { private X509CertificateCollection roots; *************** *** 63,73 **** roots = new X509CertificateCollection (); roots.AddRange (X509StoreManager.TrustedRootCertificates); - // TEMP (old method) - ITrustAnchors trust = (ITrustAnchors) new TrustAnchors (); - roots.AddRange (trust.Anchors); return roots; } return roots; } set { roots = value; } } --- 73,81 ---- roots = new X509CertificateCollection (); roots.AddRange (X509StoreManager.TrustedRootCertificates); return roots; } return roots; } + [SecurityPermission (SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlPolicy)] set { roots = value; } } *************** *** 80,86 **** } ! public void LoadCertificates (X509CertificateCollection coll) { ! certs.AddRange (coll); } --- 88,94 ---- } ! public void LoadCertificates (X509CertificateCollection collection) { ! certs.AddRange (collection); } *************** *** 176,183 **** } - #warning "Mono Service point implementation differes from MS one" - /* // TODO - we should check for CRITICAL but unknown extensions // X509ChainStatusFlags.InvalidExtension if (ServicePointManager.CheckCertificateRevocationList) { // TODO - check revocation (CRL, OCSP ...) --- 184,191 ---- } // TODO - we should check for CRITICAL but unknown extensions // X509ChainStatusFlags.InvalidExtension + /* + #if (!NET_1_0 && !INSIDE_CORLIB) if (ServicePointManager.CheckCertificateRevocationList) { // TODO - check revocation (CRL, OCSP ...) *************** *** 185,190 **** // X509ChainStatusFlags.Revoked } ! */ ! return true; } --- 193,198 ---- // X509ChainStatusFlags.Revoked } ! #endif ! */ return true; } Index: X509Extensions.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/X509Extensions.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** X509Extensions.cs 10 Feb 2004 09:46:25 -0000 1.1 --- X509Extensions.cs 9 May 2004 12:06:15 -0000 1.2 *************** *** 3,9 **** // // Author: ! // Sebastien Pouliot (spo...@mo...) // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) // --- 3,10 ---- // // Author: ! // Sebastien Pouliot <seb...@xi...> // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) // *************** *** 19,33 **** * Note: 1..MAX -> There shouldn't be 0 Extensions in the ASN1 structure */ ! internal class X509Extensions : ICollection, IEnumerable { - private ArrayList extensions; private bool readOnly; ! public X509Extensions () { - extensions = new ArrayList (); } ! public X509Extensions (ASN1 asn1) : this () { readOnly = true; --- 20,37 ---- * Note: 1..MAX -> There shouldn't be 0 Extensions in the ASN1 structure */ ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! sealed class X509ExtensionCollection : CollectionBase, IEnumerable { private bool readOnly; ! public X509ExtensionCollection () : base () { } ! public X509ExtensionCollection (ASN1 asn1) : this () { readOnly = true; *************** *** 38,101 **** for (int i=0; i < asn1.Count; i++) { X509Extension extension = new X509Extension (asn1 [i]); ! extensions.Add (extension); } } ! // ICollection ! public int Count { ! get { return extensions.Count; } } ! // ICollection ! public bool IsSynchronized { ! get { return extensions.IsSynchronized; } } ! // ICollection ! public object SyncRoot { ! get { return extensions.SyncRoot; } } ! // ICollection ! public void CopyTo (Array array, int index) { ! extensions.CopyTo (array, index); } ! // IEnumerable ! public IEnumerator GetEnumerator () { ! return extensions.GetEnumerator (); } ! public X509Extension this [int index] { ! get { return (X509Extension) extensions [index]; } } ! public X509Extension this [string index] { ! get { ! for (int i=0; i < extensions.Count; i++) { ! X509Extension extension = (X509Extension) extensions [i]; ! if (extension.OID == index) ! return extension; ! } ! return null; } } ! public void Add (X509Extension extension) { ! if (readOnly) ! throw new NotSupportedException ("Extensions are read only"); ! extensions.Add (extension); } public byte[] GetBytes () { ! if (extensions.Count < 1) return null; ASN1 sequence = new ASN1 (0x30); ! for (int i=0; i < extensions.Count; i++) { ! X509Extension x = (X509Extension) extensions [i]; sequence.Add (x.ASN1); } --- 42,176 ---- for (int i=0; i < asn1.Count; i++) { X509Extension extension = new X509Extension (asn1 [i]); ! InnerList.Add (extension); } } ! public int Add (X509Extension extension) ! { ! if (extension == null) ! throw new ArgumentNullException ("extension"); ! if (readOnly) ! throw new NotSupportedException ("Extensions are read only"); ! ! return InnerList.Add (extension); } ! public void AddRange (X509Extension[] extension) ! { ! if (extension == null) ! throw new ArgumentNullException ("extension"); ! if (readOnly) ! throw new NotSupportedException ("Extensions are read only"); ! ! for (int i = 0; i < extension.Length; i++) ! InnerList.Add (extension [i]); } + + public void AddRange (X509ExtensionCollection collection) + { + if (collection == null) + throw new ArgumentNullException ("collection"); + if (readOnly) + throw new NotSupportedException ("Extensions are read only"); ! for (int i = 0; i < collection.InnerList.Count; i++) ! InnerList.Add (collection [i]); } ! public bool Contains (X509Extension extension) { ! return (IndexOf (extension) != -1); } ! public bool Contains (string oid) { ! return (IndexOf (oid) != -1); } ! public void CopyTo (X509Extension[] extensions, int index) ! { ! if (extensions == null) ! throw new ArgumentNullException ("extensions"); ! ! InnerList.CopyTo (extensions, index); } ! public int IndexOf (X509Extension extension) ! { ! if (extension == null) ! throw new ArgumentNullException ("extension"); ! ! for (int i=0; i < InnerList.Count; i++) { ! X509Extension ex = (X509Extension) InnerList [i]; ! if (ex.Equals (extension)) ! return i; } + return -1; } ! public int IndexOf (string oid) { ! if (oid == null) ! throw new ArgumentNullException ("oid"); ! ! for (int i=0; i < InnerList.Count; i++) { ! X509Extension ex = (X509Extension) InnerList [i]; ! if (ex.Oid == oid) ! return i; ! } ! return -1; ! } ! ! public void Insert (int index, X509Extension extension) ! { ! if (extension == null) ! throw new ArgumentNullException ("extension"); ! ! InnerList.Insert (index, extension); ! } ! ! public void Remove (X509Extension extension) ! { ! if (extension == null) ! throw new ArgumentNullException ("extension"); ! ! InnerList.Remove (extension); ! } ! ! public void Remove (string oid) ! { ! if (oid == null) ! throw new ArgumentNullException ("oid"); ! ! int index = IndexOf (oid); ! if (index != -1) ! InnerList.RemoveAt (index); ! } ! ! IEnumerator IEnumerable.GetEnumerator () ! { ! return InnerList.GetEnumerator (); ! } ! ! public X509Extension this [int index] { ! get { return (X509Extension) InnerList [index]; } ! } ! ! public X509Extension this [string oid] { ! get { ! int index = IndexOf (oid); ! if (index == -1) ! return null; ! return (X509Extension) InnerList [index]; ! } } public byte[] GetBytes () { ! if (InnerList.Count < 1) return null; ASN1 sequence = new ASN1 (0x30); ! for (int i=0; i < InnerList.Count; i++) { ! X509Extension x = (X509Extension) InnerList [i]; sequence.Add (x.ASN1); } Index: X509ChainStatusFlags.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/X509ChainStatusFlags.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** X509ChainStatusFlags.cs 5 Mar 2004 23:18:17 -0000 1.1 --- X509ChainStatusFlags.cs 9 May 2004 12:06:15 -0000 1.2 *************** *** 16,20 **** [Serializable] ! internal enum X509ChainStatusFlags { // CtlNotSignatureValid = 262144, // CtlNotTimeValid = 131072, --- 16,26 ---- [Serializable] ! [Flags] ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! enum X509ChainStatusFlags { // CtlNotSignatureValid = 262144, // CtlNotTimeValid = 131072, Index: X520Attributes.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/X520Attributes.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** X520Attributes.cs 5 Mar 2004 23:18:17 -0000 1.2 --- X520Attributes.cs 9 May 2004 12:06:15 -0000 1.3 *************** *** 3,9 **** // // Author: ! // Sebastien Pouliot (spo...@mo...) // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) // --- 3,10 ---- // // Author: ! // Sebastien Pouliot <seb...@xi...> // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) // *************** *** 31,49 **** * AttributeValue ::= ANY DEFINED BY AttributeType */ ! internal class X520 { ! internal abstract class AttributeTypeAndValue { ! protected string oid; ! protected string attrValue; private int upperBound; ! private byte inputEncoding; ! protected byte defaultEncoding; ! public AttributeTypeAndValue (string oid, int upperBound) { - inputEncoding = 0xFF; - defaultEncoding = 0xFF; this.oid = oid; this.upperBound = upperBound; } --- 32,60 ---- * AttributeValue ::= ANY DEFINED BY AttributeType */ ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class X520 { ! public abstract class AttributeTypeAndValue { ! private string oid; ! private string attrValue; private int upperBound; ! private byte encoding; ! protected AttributeTypeAndValue (string oid, int upperBound) { this.oid = oid; this.upperBound = upperBound; + this.encoding = 0xFF; + } + + protected AttributeTypeAndValue (string oid, int upperBound, byte encoding) + { + this.oid = oid; + this.upperBound = upperBound; + this.encoding = encoding; } *************** *** 57,65 **** } ! public ASN1 GetASN1 (byte encoding) { ASN1 asn1 = new ASN1 (0x30); ! asn1.Add (ASN1Convert.FromOID (oid)); ! switch (encoding) { case 0x13: // PRINTABLESTRING --- 68,80 ---- } ! internal ASN1 GetASN1 (byte encoding) { + byte encode = encoding; + if (encode == 0xFF) + encode = SelectBestEncoding (); + ASN1 asn1 = new ASN1 (0x30); ! asn1.Add (ASN1Convert.FromOid (oid)); ! switch (encode) { case 0x13: // PRINTABLESTRING *************** *** 74,84 **** } ! public ASN1 GetASN1 () { - byte encoding = inputEncoding; - if (encoding == 0xFF) - encoding = defaultEncoding; - if (encoding == 0xFF) - encoding = SelectBestEncoding (); return GetASN1 (encoding); } --- 89,94 ---- } ! internal ASN1 GetASN1 () { return GetASN1 (encoding); } *************** *** 104,135 **** } ! internal class Name : AttributeTypeAndValue { ! public Name () : base ("2.5.4.41", 32768) {} } ! internal class CommonName : AttributeTypeAndValue { ! public CommonName () : base ("2.5.4.3", 64) {} } ! internal class LocalityName : AttributeTypeAndValue { ! public LocalityName () : base ("2.5.4.7", 128) {} } ! internal class StateOrProvinceName : AttributeTypeAndValue { ! public StateOrProvinceName () : base ("2.5.4.8", 128) {} } ! internal class OrganizationName : AttributeTypeAndValue { ! public OrganizationName () : base ("2.5.4.10", 64) {} } ! internal class OrganizationalUnitName : AttributeTypeAndValue { ! public OrganizationalUnitName () : base ("2.5.4.11", 64) {} } --- 114,157 ---- } ! public class Name : AttributeTypeAndValue { ! public Name () : base ("2.5.4.41", 32768) ! { ! } } ! public class CommonName : AttributeTypeAndValue { ! public CommonName () : base ("2.5.4.3", 64) ! { ! } } ! public class LocalityName : AttributeTypeAndValue { ! public LocalityName () : base ("2.5.4.7", 128) ! { ! } } ! public class StateOrProvinceName : AttributeTypeAndValue { ! public StateOrProvinceName () : base ("2.5.4.8", 128) ! { ! } } ! public class OrganizationName : AttributeTypeAndValue { ! public OrganizationName () : base ("2.5.4.10", 64) ! { ! } } ! public class OrganizationalUnitName : AttributeTypeAndValue { ! public OrganizationalUnitName () : base ("2.5.4.11", 64) ! { ! } } *************** *** 145,158 **** * } */ ! internal class Title : AttributeTypeAndValue { public Title () : base ("2.5.4.12", 64) {} } ! internal class CountryName : AttributeTypeAndValue { ! public CountryName () : base ("2.5.4.6", 2) { - defaultEncoding = 0x13; // PRINTABLESTRING } } --- 167,180 ---- * } */ ! public class Title : AttributeTypeAndValue { public Title () : base ("2.5.4.12", 64) {} } ! public class CountryName : AttributeTypeAndValue { ! // (0x13) PRINTABLESTRING ! public CountryName () : base ("2.5.4.6", 2, 0x13) { } } Index: X501Name.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/X501Name.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** X501Name.cs 10 Feb 2004 09:46:25 -0000 1.1 --- X501Name.cs 9 May 2004 12:06:15 -0000 1.2 *************** *** 3,12 **** // // Author: ! // Sebastien Pouliot (spo...@mo...) // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) // using System; using System.Text; --- 3,14 ---- // // Author: ! // Sebastien Pouliot <seb...@xi...> // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) // using System; + using System.Globalization; using System.Text; *************** *** 28,32 **** * RelativeDistinguishedName ::= SET OF AttributeTypeAndValue */ ! internal class X501 { static byte[] countryName = { 0x55, 0x04, 0x06 }; --- 30,39 ---- * RelativeDistinguishedName ::= SET OF AttributeTypeAndValue */ ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! sealed class X501 { static byte[] countryName = { 0x55, 0x04, 0x06 }; *************** *** 42,45 **** --- 49,56 ---- static byte[] email = { 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01 }; + private X501 () + { + } + static public string ToString (ASN1 seq) { *************** *** 80,84 **** // unknown OID sb.Append ("OID."); // NOTE: Not present as RFC2253 ! sb.Append (ASN1Convert.ToOID (poid)); sb.Append ("="); } --- 91,95 ---- // unknown OID sb.Append ("OID."); // NOTE: Not present as RFC2253 ! sb.Append (ASN1Convert.ToOid (poid)); sb.Append ("="); } *************** *** 115,121 **** } ! static private X520.AttributeTypeAndValue GetAttributeFromOID (string attributeType) { ! switch (attributeType.ToUpper ().Trim ()) { case "C": return new X520.CountryName (); --- 126,132 ---- } ! static private X520.AttributeTypeAndValue GetAttributeFromOid (string attributeType) { ! switch (attributeType.ToUpper (CultureInfo.InvariantCulture).Trim ()) { case "C": return new X520.CountryName (); *************** *** 160,164 **** string attributeValue = av.Substring (equal + 1); ! X520.AttributeTypeAndValue atv = GetAttributeFromOID (attributeType); atv.Value = attributeValue; asn1.Add (new ASN1 (0x31, atv.GetBytes ())); --- 171,175 ---- string attributeValue = av.Substring (equal + 1); ! X520.AttributeTypeAndValue atv = GetAttributeFromOid (attributeType); atv.Value = attributeValue; asn1.Add (new ASN1 (0x31, atv.GetBytes ())); Index: X509CertificateCollection.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/X509CertificateCollection.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** X509CertificateCollection.cs 5 Mar 2004 23:18:17 -0000 1.2 --- X509CertificateCollection.cs 9 May 2004 12:06:15 -0000 1.3 *************** *** 14,20 **** [Serializable] ! internal class X509CertificateCollection : CollectionBase, IEnumerable { ! public X509CertificateCollection () {} public X509CertificateCollection (X509Certificate [] value) --- 14,27 ---- [Serializable] ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class X509CertificateCollection : CollectionBase, IEnumerable { ! public X509CertificateCollection () ! { ! } public X509CertificateCollection (X509Certificate [] value) *************** *** 131,135 **** // Inner Class ! internal class X509CertificateEnumerator : IEnumerator { private IEnumerator enumerator; --- 138,142 ---- // Inner Class ! public class X509CertificateEnumerator : IEnumerator { private IEnumerator enumerator; *************** *** 176,178 **** } } - --- 183,184 ---- Index: X509CertificateBuilder.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/X509CertificateBuilder.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** X509CertificateBuilder.cs 5 Mar 2004 23:18:17 -0000 1.1 --- X509CertificateBuilder.cs 9 May 2004 12:06:15 -0000 1.2 *************** *** 3,9 **** // // Author: ! // Sebastien Pouliot (spo...@mo...) // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) using System; --- 3,11 ---- // // Author: ! // Sebastien Pouliot <seb...@xi...> // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) + // using System; *************** *** 44,48 **** * } */ ! internal class X509CertificateBuilder : X509Builder { private byte version; --- 46,50 ---- * } */ ! public class X509CertificateBuilder : X509Builder { private byte version; *************** *** 55,59 **** private byte[] issuerUniqueID; private byte[] subjectUniqueID; ! private X509Extensions extensions; public X509CertificateBuilder () : this (3) {} --- 57,61 ---- private byte[] issuerUniqueID; private byte[] subjectUniqueID; ! private X509ExtensionCollection extensions; public X509CertificateBuilder () : this (3) {} *************** *** 64,68 **** throw new ArgumentException ("Invalid certificate version"); this.version = version; ! extensions = new X509Extensions (); } --- 66,70 ---- throw new ArgumentException ("Invalid certificate version"); this.version = version; ! extensions = new X509ExtensionCollection (); } *************** *** 102,116 **** } ! public byte[] IssuerUniqueID { get { return issuerUniqueID; } set { issuerUniqueID = value; } } ! public byte[] SubjectUniqueID { get { return subjectUniqueID; } set { subjectUniqueID = value; } } ! public X509Extensions Extensions { get { return extensions; } } --- 104,118 ---- } ! public byte[] IssuerUniqueId { get { return issuerUniqueID; } set { issuerUniqueID = value; } } ! public byte[] SubjectUniqueId { get { return subjectUniqueID; } set { subjectUniqueID = value; } } ! public X509ExtensionCollection Extensions { get { return extensions; } } *************** *** 163,167 **** // first byte in a BITSTRING is the number of unused bits in the first byte byte[] v = new byte [id.Length + 1]; ! Array.Copy (id, 0, v, 1, id.Length); uid.Value = v; return uid.GetBytes (); --- 165,169 ---- // first byte in a BITSTRING is the number of unused bits in the first byte byte[] v = new byte [id.Length + 1]; ! Buffer.BlockCopy (id, 0, v, 1, id.Length); uid.Value = v; return uid.GetBytes (); Index: PKCS12.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/PKCS12.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PKCS12.cs 5 Mar 2004 23:18:17 -0000 1.1 --- PKCS12.cs 9 May 2004 12:06:15 -0000 1.2 *************** *** 3,9 **** // // Author: ! // Sebastien Pouliot (spo...@mo...) // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) // // Key derivation translated from Bouncy Castle JCE (http://www.bouncycastle.org/) --- 3,10 ---- // // Author: ! // Sebastien Pouliot <seb...@xi...> // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) // // Key derivation translated from Bouncy Castle JCE (http://www.bouncycastle.org/) *************** *** 22,26 **** namespace Mono.Security.X509 { ! internal class PKCS5 { public const string pbeWithMD2AndDESCBC = "1.2.840.113549.1.5.1"; --- 23,32 ---- namespace Mono.Security.X509 { ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class PKCS5 { public const string pbeWithMD2AndDESCBC = "1.2.840.113549.1.5.1"; *************** *** 34,38 **** } ! internal class PKCS12 { public const string pbeWithSHAAnd128BitRC4 = "1.2.840.113549.1.12.1.1"; --- 40,49 ---- } ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class PKCS12 { public const string pbeWithSHAAnd128BitRC4 = "1.2.840.113549.1.12.1.1"; *************** *** 203,210 **** --- 214,225 ---- } + static private int recommendedIterationCount = 2000; + private int _version; private byte[] _password; private ArrayList _keyBags; private X509CertificateCollection _certs; + private int _iterations; + private RandomNumberGenerator _rng; // constructors *************** *** 212,215 **** --- 227,231 ---- public PKCS12 () { + _iterations = recommendedIterationCount; _keyBags = new ArrayList (); _certs = new X509CertificateCollection (); *************** *** 255,259 **** PKCS7.ContentInfo authSafe = new PKCS7.ContentInfo (pfx [1]); ! if (authSafe.ContentType != PKCS7.data) throw new ArgumentException ("invalid authenticated safe"); --- 271,275 ---- PKCS7.ContentInfo authSafe = new PKCS7.ContentInfo (pfx [1]); ! if (authSafe.ContentType != PKCS7.Oid.data) throw new ArgumentException ("invalid authenticated safe"); *************** *** 269,273 **** throw new ArgumentException ("invalid MAC"); ASN1 macAlgorithm = mac [0]; ! string macOid = ASN1Convert.ToOID (macAlgorithm [0]); if (macOid != "1.3.14.3.2.26") throw new ArgumentException ("unsupported HMAC"); --- 285,289 ---- throw new ArgumentException ("invalid MAC"); ASN1 macAlgorithm = mac [0]; ! string macOid = ASN1Convert.ToOid (macAlgorithm [0]); if (macOid != "1.3.14.3.2.26") throw new ArgumentException ("unsupported HMAC"); *************** *** 278,299 **** throw new ArgumentException ("missing MAC salt"); ! int iterations = 1; // default value if (macData.Count > 2) { ASN1 iters = macData [2]; if (iters.Tag != 0x02) throw new ArgumentException ("invalid MAC iteration"); ! iterations = ASN1Convert.ToInt32 (iters); } - PKCS12.DeriveBytes pd = new PKCS12.DeriveBytes (); - pd.HashName = "SHA1"; - pd.Password = _password; - pd.Salt = macSalt.Value; - pd.IterationCount = iterations; - - HMACSHA1 hmac = (HMACSHA1) HMACSHA1.Create (); - hmac.Key = pd.DeriveMAC (20); byte[] authSafeData = authSafe.Content [0].Value; ! byte[] calculatedMac = hmac.ComputeHash (authSafeData, 0, authSafeData.Length); if (!Compare (macValue, calculatedMac)) throw new CryptographicException ("Invalid MAC - file may have been tampered!"); --- 294,307 ---- throw new ArgumentException ("missing MAC salt"); ! _iterations = 1; // default value if (macData.Count > 2) { ASN1 iters = macData [2]; if (iters.Tag != 0x02) throw new ArgumentException ("invalid MAC iteration"); ! _iterations = ASN1Convert.ToInt32 (iters); } byte[] authSafeData = authSafe.Content [0].Value; ! byte[] calculatedMac = MAC (_password, macSalt.Value, _iterations, authSafeData); if (!Compare (macValue, calculatedMac)) throw new CryptographicException ("Invalid MAC - file may have been tampered!"); *************** *** 305,309 **** PKCS7.ContentInfo ci = new PKCS7.ContentInfo (authenticatedSafe [i]); switch (ci.ContentType) { ! case PKCS7.data: // unencrypted (by PKCS#12) ASN1 safeContents = new ASN1 (ci.Content [0].Value); --- 313,317 ---- PKCS7.ContentInfo ci = new PKCS7.ContentInfo (authenticatedSafe [i]); switch (ci.ContentType) { ! case PKCS7.Oid.data: // unencrypted (by PKCS#12) ASN1 safeContents = new ASN1 (ci.Content [0].Value); *************** *** 313,317 **** } break; ! case PKCS7.encryptedData: // password encrypted PKCS7.EncryptedData ed = new PKCS7.EncryptedData (ci.Content [0]); --- 321,325 ---- } break; ! case PKCS7.Oid.encryptedData: // password encrypted PKCS7.EncryptedData ed = new PKCS7.EncryptedData (ci.Content [0]); *************** *** 322,326 **** } break; ! case PKCS7.envelopedData: // public key encrypted throw new NotImplementedException ("public key encrypted"); --- 330,334 ---- } break; ! case PKCS7.Oid.envelopedData: // public key encrypted throw new NotImplementedException ("public key encrypted"); *************** *** 353,356 **** --- 361,369 ---- } + public int IterationCount { + get { return _iterations; } + set { _iterations = value; } + } + public ArrayList Keys { get { return _keyBags; } *************** *** 361,364 **** --- 374,385 ---- } + internal RandomNumberGenerator RNG { + get { + if (_rng == null) + _rng = RandomNumberGenerator.Create (); + return _rng; + } + } + // private methods *************** *** 376,380 **** } ! public byte[] Decrypt (string algorithmOid, byte[] salt, int iterationCount, byte[] encryptedData) { string algorithm = null; --- 397,401 ---- } ! private SymmetricAlgorithm GetSymmetricAlgorithm (string algorithmOid, byte[] salt, int iterationCount) { string algorithm = null; *************** *** 464,469 **** sa.Mode = CipherMode.CBC; } ! ICryptoTransform ct = sa.CreateDecryptor (); ! return ct.TransformFinalBlock (encryptedData, 0, encryptedData.Length); } --- 485,505 ---- sa.Mode = CipherMode.CBC; } ! return sa; ! } ! ! public byte[] Decrypt (string algorithmOid, byte[] salt, int iterationCount, byte[] encryptedData) ! { ! SymmetricAlgorithm sa = null; ! byte[] result = null; ! try { ! sa = GetSymmetricAlgorithm (algorithmOid, salt, iterationCount); ! ICryptoTransform ct = sa.CreateDecryptor (); ! result = ct.TransformFinalBlock (encryptedData, 0, encryptedData.Length); ! } ! finally { ! if (sa != null) ! sa.Clear (); ! } ! return result; } *************** *** 476,479 **** --- 512,525 ---- } + public byte[] Encrypt (string algorithmOid, byte[] salt, int iterationCount, byte[] data) + { + byte[] result = null; + using (SymmetricAlgorithm sa = GetSymmetricAlgorithm (algorithmOid, salt, iterationCount)) { + ICryptoTransform ct = sa.CreateEncryptor (); + result = ct.TransformFinalBlock (data, 0, data.Length); + } + return result; + } + private void AddPrivateKey (PKCS8.PrivateKeyInfo pki) { *************** *** 504,508 **** ASN1 bagValue = safeBag [1]; ! string oid = ASN1Convert.ToOID (bagId); switch (oid) { case keyBag: --- 550,554 ---- ASN1 bagValue = safeBag [1]; ! string oid = ASN1Convert.ToOid (bagId); switch (oid) { case keyBag: *************** *** 537,543 **** } ! static private int recommendedIterationCount = 2000; ! /* * SafeContents ::= SEQUENCE OF SafeBag * --- 583,640 ---- } ! private ASN1 Pkcs8ShroudedKeyBag (AsymmetricAlgorithm aa) ! { ! PKCS8.PrivateKeyInfo pki = new PKCS8.PrivateKeyInfo (); ! if (aa is RSA) { ! pki.Algorithm = "1.2.840.113549.1.1.1"; ! pki.PrivateKey = PKCS8.PrivateKeyInfo.Encode ((RSA)aa); ! } ! else if (aa is DSA) { ! pki.Algorithm = null; ! pki.PrivateKey = PKCS8.PrivateKeyInfo.Encode ((DSA)aa); ! } ! else ! throw new CryptographicException ("Unknown asymmetric algorithm {0}", aa.ToString ()); ! PKCS8.EncryptedPrivateKeyInfo epki = new PKCS8.EncryptedPrivateKeyInfo (); ! epki.Algorithm = pbeWithSHAAnd3KeyTripleDESCBC; ! epki.IterationCount = _iterations; ! epki.EncryptedData = Encrypt (pbeWithSHAAnd3KeyTripleDESCBC, epki.Salt, _iterations, pki.GetBytes ()); ! ! return new ASN1 (epki.GetBytes ()); ! } ! ! private ASN1 CertificateSafeBag (X509Certificate x509) ! { ! ASN1 encapsulatedCertificate = new ASN1 (0x04, x509.RawData); ! ! PKCS7.ContentInfo ci = new PKCS7.ContentInfo (); ! ci.ContentType = x509Certificate; ! ci.Content.Add (encapsulatedCertificate); ! ! ASN1 bagValue = new ASN1 (0xA0); ! bagValue.Add (ci.ASN1); ! ! ASN1 safeBag = new ASN1 (0x30); ! safeBag.Add (ASN1Convert.FromOid (certBag)); ! safeBag.Add (bagValue); ! ! return safeBag; ! } ! ! private byte[] MAC (byte[] password, byte[] salt, int iterations, byte[] data) ! { ! PKCS12.DeriveBytes pd = new PKCS12.DeriveBytes (); ! pd.HashName = "SHA1"; ! pd.Password = password; ! pd.Salt = salt; ! pd.IterationCount = iterations; ! ! HMACSHA1 hmac = (HMACSHA1) HMACSHA1.Create (); ! hmac.Key = pd.DeriveMAC (20); ! return hmac.ComputeHash (data, 0, data.Length); ! } ! ! /* * SafeContents ::= SEQUENCE OF SafeBag * *************** *** 550,572 **** public byte[] GetBytes () { - PKCS7.ContentInfo authSafe = new PKCS7.ContentInfo (PKCS7.data); - // TODO (incomplete) byte[] salt = new byte [20]; ! RandomNumberGenerator rng = RandomNumberGenerator.Create (); ! rng.GetBytes (salt); ASN1 macData = new ASN1 (0x30); ! byte[] macValue = null; if (macValue != null) { // only for password based encryption ASN1 mac = new ASN1 (0x30); ! mac.Add (ASN1Convert.FromOID ("1.3.14.3.2.26")); // SHA1 mac.Add (new ASN1 (0x04, macValue)); macData.Add (mac); macData.Add (new ASN1 (0x04, salt)); ! macData.Add (ASN1Convert.FromInt32 (recommendedIterationCount)); } --- 647,734 ---- public byte[] GetBytes () { // TODO (incomplete) + ASN1 safeBagSequence = new ASN1 (0x30); + + if (_certs.Count > 0) { + byte[] certsSalt = new byte [8]; + RNG.GetBytes (certsSalt); + + ASN1 seqParams = new ASN1 (0x30); + seqParams.Add (new ASN1 (0x04, certsSalt)); + seqParams.Add (ASN1Convert.FromInt32 (_iterations)); + + ASN1 seqPbe = new ASN1 (0x30); + seqPbe.Add (ASN1Convert.FromOid (pbeWithSHAAnd3KeyTripleDESCBC)); + seqPbe.Add (seqParams); + + ASN1 certsSafeBag = new ASN1 (0x30); + foreach (X509Certificate x in _certs) { + ASN1 certSafeBag = CertificateSafeBag (x); + certsSafeBag.Add (certSafeBag); + } + byte[] encrypted = Encrypt (pbeWithSHAAnd3KeyTripleDESCBC, certsSalt, _iterations, certsSafeBag.GetBytes ()); + ASN1 encryptedCerts = new ASN1 (0x80, encrypted); + ASN1 seq = new ASN1 (0x30); + seq.Add (ASN1Convert.FromOid (PKCS7.Oid.data)); + seq.Add (seqPbe); + seq.Add (encryptedCerts); + + ASN1 certsVersion = new ASN1 (0x02, new byte [1] { 0x00 }); + ASN1 encData = new ASN1 (0x30); + encData.Add (certsVersion); + encData.Add (seq); + + ASN1 certsContent = new ASN1 (0xA0); + certsContent.Add (encData); + + PKCS7.ContentInfo bag = new PKCS7.ContentInfo (PKCS7.Oid.encryptedData); + bag.Content = certsContent; + safeBagSequence.Add (bag.ASN1); + } + + if (_keyBags.Count > 0) { + ASN1 safeContents = new ASN1 (0x30); + foreach (AsymmetricAlgorithm key in _keyBags) { + ASN1 safeBag = new ASN1 (0x30); + safeBag.Add (ASN1Convert.FromOid (pkcs8ShroudedKeyBag)); + ASN1 safeBagValue = new ASN1 (0xA0); + safeBagValue.Add (Pkcs8ShroudedKeyBag (key)); + safeBag.Add (safeBagValue); + safeContents.Add (safeBag); + } + + ASN1 content = new ASN1 (0xA0); + content.Add (new ASN1 (0x04, safeContents.GetBytes ())); + + PKCS7.ContentInfo keyBag = new PKCS7.ContentInfo (PKCS7.Oid.data); + keyBag.Content = content; + safeBagSequence.Add (keyBag.ASN1); + } + + ASN1 encapsulates = new ASN1 (0x04, safeBagSequence.GetBytes ()); + ASN1 ci = new ASN1 (0xA0); + ci.Add (encapsulates); + PKCS7.ContentInfo authSafe = new PKCS7.ContentInfo (PKCS7.Oid.data); + authSafe.Content = ci; + byte[] salt = new byte [20]; ! RNG.GetBytes (salt); ASN1 macData = new ASN1 (0x30); ! byte[] macValue = MAC (_password, salt, _iterations, authSafe.Content [0].Value); if (macValue != null) { // only for password based encryption + ASN1 oidSeq = new ASN1 (0x30); + oidSeq.Add (ASN1Convert.FromOid ("1.3.14.3.2.26")); // SHA1 + oidSeq.Add (new ASN1 (0x05)); + ASN1 mac = new ASN1 (0x30); ! mac.Add (oidSeq); mac.Add (new ASN1 (0x04, macValue)); macData.Add (mac); macData.Add (new ASN1 (0x04, salt)); ! macData.Add (ASN1Convert.FromInt32 (_iterations)); } *************** *** 584,587 **** --- 746,759 ---- } + public void SaveToFile (string filename) + { + using (FileStream fs = File.OpenWrite (filename)) { + byte[] data = GetBytes (); + fs.Write (data, 0, data.Length); + fs.Flush (); + fs.Close (); + } + } + // static methods *************** *** 609,614 **** if (filename == null) throw new ArgumentNullException ("filename"); - if (password == null) - throw new ArgumentNullException ("password"); return new PKCS12 (LoadFile (filename), password); --- 781,784 ---- Index: X509Store.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/X509Store.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** X509Store.cs 5 Mar 2004 23:18:17 -0000 1.1 --- X509Store.cs 9 May 2004 12:06:15 -0000 1.2 *************** *** 10,13 **** --- 10,14 ---- using System; using System.Collections; + using System.Globalization; using System.IO; using System.Text; *************** *** 17,21 **** namespace Mono.Security.X509 { ! internal class X509Store { private string _storePath; --- 18,27 ---- namespace Mono.Security.X509 { ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class X509Store { private string _storePath; *************** *** 42,46 **** } ! public ArrayList CRLs { get { // CRL aren't applicable to all stores --- 48,52 ---- } ! public ArrayList Crls { get { // CRL aren't applicable to all stores *************** *** 50,54 **** } if (_crls == null) { ! _crls = BuildCRLsCollection (_storePath); } return _crls; --- 56,60 ---- } if (_crls == null) { ! _crls = BuildCrlsCollection (_storePath); } return _crls; *************** *** 125,129 **** sb.Append ("-"); foreach (byte b in name) { ! sb.Append (b.ToString ("X2")); } sb.Append (".cer"); --- 131,135 ---- sb.Append ("-"); foreach (byte b in name) { ! sb.Append (b.ToString ("X2", CultureInfo.InvariantCulture)); } sb.Append (".cer"); *************** *** 150,157 **** } ! private X509CRL LoadCRL (string filename) { byte[] data = Load (filename); ! X509CRL crl = new X509CRL (data); return crl; } --- 156,163 ---- } ! private X509Crl LoadCrl (string filename) { byte[] data = Load (filename); ! X509Crl crl = new X509Crl (data); return crl; } *************** *** 183,187 **** } ! private ArrayList BuildCRLsCollection (string storeName) { ArrayList list = new ArrayList (); --- 189,193 ---- } ! private ArrayList BuildCrlsCollection (string storeName) { ArrayList list = new ArrayList (); *************** *** 191,195 **** foreach (string file in files) { try { ! X509CRL crl = LoadCRL (file); list.Add (crl); } --- 197,201 ---- foreach (string file in files) { try { ! X509Crl crl = LoadCrl (file); list.Add (crl); } Index: X509Builder.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/X509Builder.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** X509Builder.cs 5 Mar 2004 23:18:17 -0000 1.1 --- X509Builder.cs 9 May 2004 12:06:15 -0000 1.2 *************** *** 1,3 **** --- 1,14 ---- + // + // X509Builder.cs: Abstract builder class for X509 objects + // + // Author: + // Sebastien Pouliot <seb...@xi...> + // + // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) + // + using System; + using System.Globalization; using System.Security.Cryptography; *************** *** 6,15 **** namespace Mono.Security.X509 { ! internal abstract class X509Builder { private const string defaultHash = "SHA1"; private string hashName; ! public X509Builder () { hashName = defaultHash; --- 17,26 ---- namespace Mono.Security.X509 { ! public abstract class X509Builder { private const string defaultHash = "SHA1"; private string hashName; ! protected X509Builder () { hashName = defaultHash; *************** *** 19,25 **** // move to PKCS1 ! protected string GetOID (string hashName) { ! switch (hashName.ToLower ()) { case "md2": // md2withRSAEncryption (1 2 840 113549 1 1 2) --- 30,36 ---- // move to PKCS1 ! protected string GetOid (string hashName) { ! switch (hashName.ToLower (CultureInfo.InvariantCulture)) { case "md2": // md2withRSAEncryption (1 2 840 113549 1 1 2) *************** *** 75,79 **** // first byte of BITSTRING is the number of unused bits in the first byte byte[] bitstring = new byte [signature.Length + 1]; ! Array.Copy (signature, 0, bitstring, 1, signature.Length); builder.Add (new ASN1 (0x03, bitstring)); return builder.GetBytes (); --- 86,90 ---- // first byte of BITSTRING is the number of unused bits in the first byte byte[] bitstring = new byte [signature.Length + 1]; ! Buffer.BlockCopy (signature, 0, bitstring, 1, signature.Length); builder.Add (new ASN1 (0x03, bitstring)); return builder.GetBytes (); *************** *** 82,86 **** public virtual byte[] Sign (RSA key) { ! string oid = GetOID (hashName); ASN1 tbs = ToBeSigned (oid); HashAlgorithm ha = HashAlgorithm.Create (hashName); --- 93,97 ---- public virtual byte[] Sign (RSA key) { ! string oid = GetOid (hashName); ASN1 tbs = ToBeSigned (oid); HashAlgorithm ha = HashAlgorithm.Create (hashName); *************** *** 109,115 **** // split R and S byte[] r = new byte [20]; ! Array.Copy (rs, 0, r, 0, 20); byte[] s = new byte [20]; ! Array.Copy (rs, 20, s, 0, 20); ASN1 signature = new ASN1 (0x30); signature.Add (new ASN1 (0x02, r)); --- 120,126 ---- // split R and S byte[] r = new byte [20]; ! Buffer.BlockCopy (rs, 0, r, 0, 20); byte[] s = new byte [20]; ! Buffer.BlockCopy (rs, 20, s, 0, 20); ASN1 signature = new ASN1 (0x30); signature.Add (new ASN1 (0x02, r)); Index: TrustAnchors.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/TrustAnchors.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TrustAnchors.cs 5 Mar 2004 23:18:17 -0000 1.2 --- TrustAnchors.cs 9 May 2004 12:06:15 -0000 1.3 *************** *** 12,16 **** namespace Mono.Security.X509 { ! internal class TrustAnchors : ITrustAnchors { static byte[] msroot = { --- 12,21 ---- namespace Mono.Security.X509 { ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class TrustAnchors : ITrustAnchors { static byte[] msroot = { Index: X509CRL.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.X509/X509CRL.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** X509CRL.cs 5 Mar 2004 23:18:17 -0000 1.1 --- X509CRL.cs 9 May 2004 12:06:15 -0000 1.2 *************** *** 10,13 **** --- 10... [truncated message content] |
From: Carlos Guzm?n ?l. <car...@us...> - 2004-05-09 12:05:59
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30110 Modified Files: TlsServerCertificate.cs Log Message: Sync Mono.Security stuff wit Mono Beta 1 sources Index: TlsServerCertificate.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Client/TlsServerCertificate.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TlsServerCertificate.cs 21 Apr 2004 12:54:53 -0000 1.10 --- TlsServerCertificate.cs 9 May 2004 12:05:48 -0000 1.11 *************** *** 122,136 **** return true; ! KeyUsage ku = KeyUsage.none; switch (context.Cipher.ExchangeAlgorithmType) { case ExchangeAlgorithmType.RsaSign: ! ku = KeyUsage.digitalSignature; break; case ExchangeAlgorithmType.RsaKeyX: ! ku = KeyUsage.keyEncipherment; break; case ExchangeAlgorithmType.DiffieHellman: ! ku = KeyUsage.keyAgreement; break; case ExchangeAlgorithmType.Fortezza: --- 122,136 ---- return true; ! KeyUsages ku = KeyUsages.none; switch (context.Cipher.ExchangeAlgorithmType) { case ExchangeAlgorithmType.RsaSign: ! ku = KeyUsages.digitalSignature; break; case ExchangeAlgorithmType.RsaKeyX: ! ku = KeyUsages.keyEncipherment; break; case ExchangeAlgorithmType.DiffieHellman: ! ku = KeyUsages.keyAgreement; break; case ExchangeAlgorithmType.Fortezza: *************** *** 172,176 **** { NetscapeCertTypeExtension ct = new NetscapeCertTypeExtension (xtn); ! return ct.Support (NetscapeCertTypeExtension.CertType.SslServer); } --- 172,176 ---- { NetscapeCertTypeExtension ct = new NetscapeCertTypeExtension (xtn); ! return ct.Support (NetscapeCertTypeExtension.CertTypes.SslServer); } *************** *** 223,227 **** chain.Remove (leaf); X509Chain verify = new X509Chain (chain); ! if (!verify.Build (leaf)) { switch (verify.Status) --- 223,239 ---- chain.Remove (leaf); X509Chain verify = new X509Chain (chain); ! ! bool result = false; ! ! try ! { ! result = !verify.Build (leaf); ! } ! catch (Exception) ! { ! result = false; ! } ! ! if (!result) { switch (verify.Status) |
From: Carlos Guzm?n ?l. <car...@us...> - 2004-05-09 12:04:46
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Cryptography In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29944 Modified Files: CryptoTools.cs PKCS1.cs PKCS8.cs RSAManaged.cs Log Message: Sync Mono.Security stuff wit Mono Beta 1 sources Index: PKCS1.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Cryptography/PKCS1.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PKCS1.cs 10 Feb 2004 09:43:04 -0000 1.1 --- PKCS1.cs 9 May 2004 12:04:34 -0000 1.2 *************** *** 17,22 **** // http://www.rsasecurity.com/rsalabs/pkcs/pkcs-1/index.html ! internal class PKCS1 { ! private static bool Compare (byte[] array1, byte[] array2) { --- 17,31 ---- // http://www.rsasecurity.com/rsalabs/pkcs/pkcs-1/index.html ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! sealed class PKCS1 { ! ! private PKCS1 () ! { ! } ! private static bool Compare (byte[] array1, byte[] array2) { *************** *** 61,65 **** public static byte[] I2OSP (int x, int size) { ! byte[] array = BitConverter.GetBytes (x); Array.Reverse (array, 0, array.Length); return I2OSP (array, size); --- 70,74 ---- public static byte[] I2OSP (int x, int size) { ! byte[] array = BitConverterLE.GetBytes (x); Array.Reverse (array, 0, array.Length); return I2OSP (array, size); *************** *** 69,73 **** { byte[] result = new byte [size]; ! Array.Copy (x, 0, result, (result.Length - x.Length), x.Length); return result; } --- 78,82 ---- { byte[] result = new byte [size]; ! Buffer.BlockCopy (x, 0, result, (result.Length - x.Length), x.Length); return result; } *************** *** 82,86 **** if (i > 0) { byte[] result = new byte [x.Length - i]; ! Array.Copy (x, i, result, 0, result.Length); return result; } --- 91,95 ---- if (i > 0) { byte[] result = new byte [x.Length - i]; ! Buffer.BlockCopy (x, i, result, 0, result.Length); return result; } *************** *** 132,138 **** // DB = lHash || PS || 0x01 || M byte[] DB = new byte [lHash.Length + PSLength + 1 + M.Length]; ! Array.Copy (lHash, 0, DB, 0, lHash.Length); DB [(lHash.Length + PSLength)] = 0x01; ! Array.Copy (M, 0, DB, (DB.Length - M.Length), M.Length); byte[] seed = new byte [hLen]; --- 141,147 ---- // DB = lHash || PS || 0x01 || M byte[] DB = new byte [lHash.Length + PSLength + 1 + M.Length]; ! Buffer.BlockCopy (lHash, 0, DB, 0, lHash.Length); DB [(lHash.Length + PSLength)] = 0x01; ! Buffer.BlockCopy (M, 0, DB, (DB.Length - M.Length), M.Length); byte[] seed = new byte [hLen]; *************** *** 145,150 **** // EM = 0x00 || maskedSeed || maskedDB byte[] EM = new byte [maskedSeed.Length + maskedDB.Length + 1]; ! Array.Copy (maskedSeed, 0, EM, 1, maskedSeed.Length); ! Array.Copy (maskedDB, 0, EM, maskedSeed.Length + 1, maskedDB.Length); byte[] m = OS2IP (EM); --- 154,159 ---- // EM = 0x00 || maskedSeed || maskedDB byte[] EM = new byte [maskedSeed.Length + maskedDB.Length + 1]; ! Buffer.BlockCopy (maskedSeed, 0, EM, 1, maskedSeed.Length); ! Buffer.BlockCopy (maskedDB, 0, EM, maskedSeed.Length + 1, maskedDB.Length); byte[] m = OS2IP (EM); *************** *** 168,174 **** // split EM = Y || maskedSeed || maskedDB byte[] maskedSeed = new byte [hLen]; ! Array.Copy (EM, 1, maskedSeed, 0, maskedSeed.Length); byte[] maskedDB = new byte [size - hLen - 1]; ! Array.Copy (EM, (EM.Length - maskedDB.Length), maskedDB, 0, maskedDB.Length); byte[] seedMask = MGF1 (hash, maskedDB, hLen); --- 177,183 ---- // split EM = Y || maskedSeed || maskedDB byte[] maskedSeed = new byte [hLen]; ! Buffer.BlockCopy (EM, 1, maskedSeed, 0, maskedSeed.Length); byte[] maskedDB = new byte [size - hLen - 1]; ! Buffer.BlockCopy (EM, (EM.Length - maskedDB.Length), maskedDB, 0, maskedDB.Length); byte[] seedMask = MGF1 (hash, maskedDB, hLen); *************** *** 180,184 **** // split DB = lHash' || PS || 0x01 || M byte[] dbHash = new byte [lHash.Length]; ! Array.Copy (DB, 0, dbHash, 0, dbHash.Length); bool h = Compare (lHash, dbHash); --- 189,193 ---- // split DB = lHash' || PS || 0x01 || M byte[] dbHash = new byte [lHash.Length]; ! Buffer.BlockCopy (DB, 0, dbHash, 0, dbHash.Length); bool h = Compare (lHash, dbHash); *************** *** 190,194 **** int Msize = DB.Length - nPos - 1; byte[] M = new byte [Msize]; ! Array.Copy (DB, (nPos + 1), M, 0, Msize); // we could have returned EM[0] sooner but would be helping a timing attack --- 199,203 ---- int Msize = DB.Length - nPos - 1; byte[] M = new byte [Msize]; ! Buffer.BlockCopy (DB, (nPos + 1), M, 0, Msize); // we could have returned EM[0] sooner but would be helping a timing attack *************** *** 210,215 **** byte[] EM = new byte [size]; EM [1] = 0x02; ! Array.Copy (PS, 0, EM, 2, PSLength); ! Array.Copy (M, 0, EM, (size - M.Length), M.Length); byte[] m = OS2IP (EM); --- 219,224 ---- byte[] EM = new byte [size]; EM [1] = 0x02; ! Buffer.BlockCopy (PS, 0, EM, 2, PSLength); ! Buffer.BlockCopy (M, 0, EM, (size - M.Length), M.Length); byte[] m = OS2IP (EM); *************** *** 241,245 **** mPos++; byte[] M = new byte [EM.Length - mPos]; ! Array.Copy (EM, mPos, M, 0, M.Length); return M; } --- 250,254 ---- mPos++; byte[] M = new byte [EM.Length - mPos]; ! Buffer.BlockCopy (EM, mPos, M, 0, M.Length); return M; } *************** *** 274,278 **** // TODO: add more validation byte[] decryptedHash = new byte [hashValue.Length]; ! Array.Copy (EM2, EM2.Length - hashValue.Length, decryptedHash, 0, decryptedHash.Length); result = Compare (decryptedHash, hashValue); } --- 283,287 ---- // TODO: add more validation byte[] decryptedHash = new byte [hashValue.Length]; ! Buffer.BlockCopy (EM2, EM2.Length - hashValue.Length, decryptedHash, 0, decryptedHash.Length); result = Compare (decryptedHash, hashValue); } *************** *** 314,318 **** } ! Array.Copy (hashValue, 0, t, t.Length - hashValue.Length, hashValue.Length); int PSLength = System.Math.Max (8, emLength - t.Length - 3); --- 323,327 ---- } ! Buffer.BlockCopy (hashValue, 0, t, t.Length - hashValue.Length, hashValue.Length); int PSLength = System.Math.Max (8, emLength - t.Length - 3); *************** *** 324,328 **** for (int i=2; i < PSLength + 2; i++) EM[i] = 0xff; ! Array.Copy (t, 0, EM, PSLength + 3, t.Length); return EM; --- 333,337 ---- for (int i=2; i < PSLength + 2; i++) EM[i] = 0xff; ! Buffer.BlockCopy (t, 0, EM, PSLength + 3, t.Length); return EM; *************** *** 355,362 **** // b. Concatenate the hash of the seed mgfSeed and C to the octet string T: // T = T || Hash (mgfSeed || C) ! Array.Copy (mgfSeed, 0, toBeHashed, 0, mgfSeedLength); ! Array.Copy (C, 0, toBeHashed, mgfSeedLength, 4); byte[] output = hash.ComputeHash (toBeHashed); ! Array.Copy (output, 0, T, pos, hLen); pos += mgfSeedLength; } --- 364,371 ---- // b. Concatenate the hash of the seed mgfSeed and C to the octet string T: // T = T || Hash (mgfSeed || C) ! Buffer.BlockCopy (mgfSeed, 0, toBeHashed, 0, mgfSeedLength); ! Buffer.BlockCopy (C, 0, toBeHashed, mgfSeedLength, 4); byte[] output = hash.ComputeHash (toBeHashed); ! Buffer.BlockCopy (output, 0, T, pos, hLen); pos += mgfSeedLength; } *************** *** 364,368 **** // 4. Output the leading maskLen octets of T as the octet string mask. byte[] mask = new byte [maskLen]; ! Array.Copy (T, 0, mask, 0, maskLen); return mask; } --- 373,377 ---- // 4. Output the leading maskLen octets of T as the octet string mask. byte[] mask = new byte [maskLen]; ! Buffer.BlockCopy (T, 0, mask, 0, maskLen); return mask; } Index: CryptoTools.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Cryptography/CryptoTools.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CryptoTools.cs 5 Mar 2004 23:15:21 -0000 1.1 --- CryptoTools.cs 9 May 2004 12:04:34 -0000 1.2 *************** *** 4,10 **** // // Authors: ! // Sebastien Pouliot (spo...@mo...) // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) // --- 4,11 ---- // // Authors: ! // Sebastien Pouliot <seb...@xi...> // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) // *************** *** 14,28 **** namespace Mono.Security.Cryptography { ! internal class KeyBuilder { static private RandomNumberGenerator rng; ! ! static KeyBuilder () { - rng = RandomNumberGenerator.Create (); } static public byte[] Key (int size) { byte[] key = new byte [size]; rng.GetBytes (key); --- 15,36 ---- namespace Mono.Security.Cryptography { ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! sealed class KeyBuilder { static private RandomNumberGenerator rng; ! ! private KeyBuilder () { } static public byte[] Key (int size) { + if (rng == null) + rng = RandomNumberGenerator.Create (); + byte[] key = new byte [size]; rng.GetBytes (key); *************** *** 32,35 **** --- 40,46 ---- static public byte[] IV (int size) { + if (rng == null) + rng = RandomNumberGenerator.Create (); + byte[] iv = new byte [size]; rng.GetBytes (iv); *************** *** 39,43 **** // Process an array as a sequence of blocks ! internal class BlockProcessor { private ICryptoTransform transform; private byte[] block; --- 50,59 ---- // Process an array as a sequence of blocks ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class BlockProcessor { private ICryptoTransform transform; private byte[] block; *************** *** 78,82 **** // 1. fill the rest of the "block" int n = System.Math.Min (blockSize - blockCount, cb); ! Array.Copy (rgb, ib, block, blockCount, n); blockCount += n; --- 94,98 ---- // 1. fill the rest of the "block" int n = System.Math.Min (blockSize - blockCount, cb); ! Buffer.BlockCopy (rgb, ib, block, blockCount, n); blockCount += n; *************** *** 95,99 **** blockCount = cb - n; if (blockCount > 0) ! Array.Copy (rgb, n, block, 0, blockCount); } } --- 111,115 ---- blockCount = cb - n; if (blockCount > 0) ! Buffer.BlockCopy (rgb, n, block, 0, blockCount); } } Index: PKCS8.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Cryptography/PKCS8.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PKCS8.cs 5 Mar 2004 23:15:21 -0000 1.1 --- PKCS8.cs 9 May 2004 12:04:34 -0000 1.2 *************** *** 4,10 **** // // Author: ! // Sebastien Pouliot (spo...@mo...) // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) // --- 4,11 ---- // // Author: ! // Sebastien Pouliot <seb...@xi...> // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) // *************** *** 19,23 **** namespace Mono.Security.Cryptography { ! internal class PKCS8 { public enum KeyInfo { --- 20,24 ---- namespace Mono.Security.Cryptography { ! public sealed class PKCS8 { public enum KeyInfo { *************** *** 27,30 **** --- 28,35 ---- } + private PKCS8 () + { + } + static public KeyInfo GetType (byte[] data) { *************** *** 99,104 **** public byte[] PrivateKey { ! get { return _key; } ! set { _key = value; } } --- 104,117 ---- public byte[] PrivateKey { ! get { ! if (_key == null) ! return null; ! return (byte[]) _key.Clone (); ! } ! set { ! if (value == null) ! throw new ArgumentNullException ("PrivateKey"); ! _key = (byte[]) value.Clone (); ! } } *************** *** 132,136 **** if (algorithm.Tag != 0x06) throw new CryptographicException ("missing algorithm OID"); ! _algorithm = ASN1Convert.ToOID (algorithm); ASN1 privateKey = privateKeyInfo [2]; --- 145,149 ---- if (algorithm.Tag != 0x06) throw new CryptographicException ("missing algorithm OID"); ! _algorithm = ASN1Convert.ToOid (algorithm); ASN1 privateKey = privateKeyInfo [2]; *************** *** 146,153 **** } - // TODO public byte[] GetBytes () { ! return null; } --- 159,182 ---- } public byte[] GetBytes () { ! ASN1 privateKeyAlgorithm = new ASN1 (0x30); ! privateKeyAlgorithm.Add (ASN1Convert.FromOid (_algorithm)); ! privateKeyAlgorithm.Add (new ASN1 (0x05)); // ASN.1 NULL ! ! ASN1 pki = new ASN1 (0x30); ! pki.Add (new ASN1 (0x02, new byte [1] { (byte) _version })); ! pki.Add (privateKeyAlgorithm); ! pki.Add (new ASN1 (0x04, _key)); ! ! if (_list.Count > 0) { ! ASN1 attributes = new ASN1 (0xA0); ! foreach (ASN1 attribute in _list) { ! attributes.Add (attribute); ! } ! pki.Add (attributes); ! } ! ! return pki.GetBytes (); } *************** *** 195,201 **** * } */ ! static public RSA DecodeRSA (byte[] encryptedKeypair) { ! ASN1 privateKey = new ASN1 (encryptedKeypair); if (privateKey.Tag != 0x30) throw new CryptographicException ("invalid private key format"); --- 224,230 ---- * } */ ! static public RSA DecodeRSA (byte[] keypair) { ! ASN1 privateKey = new ASN1 (keypair); if (privateKey.Tag != 0x30) throw new CryptographicException ("invalid private key format"); *************** *** 227,230 **** --- 256,291 ---- } + /* + * RSAPrivateKey ::= SEQUENCE { + * version Version, + * modulus INTEGER, -- n + * publicExponent INTEGER, -- e + * privateExponent INTEGER, -- d + * prime1 INTEGER, -- p + * prime2 INTEGER, -- q + * exponent1 INTEGER, -- d mod (p-1) + * exponent2 INTEGER, -- d mod (q-1) + * coefficient INTEGER, -- (inverse of q) mod p + * otherPrimeInfos OtherPrimeInfos OPTIONAL + * } + */ + static public byte[] Encode (RSA rsa) + { + RSAParameters param = rsa.ExportParameters (true); + + ASN1 rsaPrivateKey = new ASN1 (0x30); + rsaPrivateKey.Add (new ASN1 (0x02, new byte [1] { 0x00 })); + rsaPrivateKey.Add (ASN1Convert.FromUnsignedBigInteger (param.Modulus)); + rsaPrivateKey.Add (ASN1Convert.FromUnsignedBigInteger (param.Exponent)); + rsaPrivateKey.Add (ASN1Convert.FromUnsignedBigInteger (param.D)); + rsaPrivateKey.Add (ASN1Convert.FromUnsignedBigInteger (param.P)); + rsaPrivateKey.Add (ASN1Convert.FromUnsignedBigInteger (param.Q)); + rsaPrivateKey.Add (ASN1Convert.FromUnsignedBigInteger (param.DP)); + rsaPrivateKey.Add (ASN1Convert.FromUnsignedBigInteger (param.DQ)); + rsaPrivateKey.Add (ASN1Convert.FromUnsignedBigInteger (param.InverseQ)); + + return rsaPrivateKey.GetBytes (); + } + // DSA only encode it's X private key inside an ASN.1 INTEGER (Hint: Tag == 0x02) // which isn't enough for rebuilding the keypair. The other parameters *************** *** 232,247 **** // with the private key or (2% of the time) the parameters are in it's // issuer X.509 certificate (not supported in the .NET framework). ! static public DSA DecodeDSA (byte[] encryptedPrivateKey, DSAParameters dsaParameters) { ! ASN1 privateKey = new ASN1 (encryptedPrivateKey); ! if (privateKey.Tag != 0x02) throw new CryptographicException ("invalid private key format"); // X is ALWAYS 20 bytes (no matter if the key length is 512 or 1024 bits) ! dsaParameters.X = Normalize (encryptedPrivateKey, 20); DSA dsa = DSA.Create (); dsa.ImportParameters (dsaParameters); return dsa; } } --- 293,324 ---- // with the private key or (2% of the time) the parameters are in it's // issuer X.509 certificate (not supported in the .NET framework). ! static public DSA DecodeDSA (byte[] privateKey, DSAParameters dsaParameters) { ! ASN1 pvk = new ASN1 (privateKey); ! if (pvk.Tag != 0x02) throw new CryptographicException ("invalid private key format"); // X is ALWAYS 20 bytes (no matter if the key length is 512 or 1024 bits) ! dsaParameters.X = Normalize (privateKey, 20); DSA dsa = DSA.Create (); dsa.ImportParameters (dsaParameters); return dsa; } + + static public byte[] Encode (DSA dsa) + { + DSAParameters param = dsa.ExportParameters (true); + return ASN1Convert.FromUnsignedBigInteger (param.X).GetBytes (); + } + + static public byte[] Encode (AsymmetricAlgorithm aa) + { + if (aa is RSA) + return Encode ((RSA)aa); + else if (aa is DSA) + return Encode ((DSA)aa); + else + throw new CryptographicException ("Unknown asymmetric algorithm {0}", aa.ToString ()); + } } *************** *** 286,301 **** public string Algorithm { get { return _algorithm; } } public byte[] EncryptedData { ! get { return (byte[]) _data.Clone (); } } public byte[] Salt { ! get { return (byte[]) _salt.Clone (); } } public int IterationCount { get { return _iterations; } } --- 363,393 ---- public string Algorithm { get { return _algorithm; } + set { _algorithm = value; } } public byte[] EncryptedData { ! get { return (_data == null) ? null : (byte[]) _data.Clone (); } ! set { _data = (value == null) ? null : (byte[]) value.Clone (); } } public byte[] Salt { ! get { ! if (_salt == null) { ! RandomNumberGenerator rng = RandomNumberGenerator.Create (); ! _salt = new byte [8]; ! rng.GetBytes (_salt); ! } ! return (byte[]) _salt.Clone (); ! } ! set { _salt = (byte[]) value.Clone (); } } public int IterationCount { get { return _iterations; } + set { + if (value < 0) + throw new ArgumentOutOfRangeException ("IterationCount", "Negative"); + _iterations = value; + } } *************** *** 314,318 **** if (algorithm.Tag != 0x06) throw new CryptographicException ("invalid algorithm"); ! _algorithm = ASN1Convert.ToOID (algorithm); // parameters ANY DEFINED BY algorithm OPTIONAL if (encryptionAlgorithm.Count > 1) { --- 406,410 ---- if (algorithm.Tag != 0x06) throw new CryptographicException ("invalid algorithm"); ! _algorithm = ASN1Convert.ToOid (algorithm); // parameters ANY DEFINED BY algorithm OPTIONAL if (encryptionAlgorithm.Count > 1) { *************** *** 342,349 **** // Netscape: http://www.cs.auckland.ac.nz/~pgut001/pubs/netscape.txt // Microsoft: http://www.cs.auckland.ac.nz/~pgut001/pubs/breakms.txt ! public byte[] GetBytes (byte[] encryptedPrivateKey) { ! // TODO ! return null; } } --- 434,464 ---- // Netscape: http://www.cs.auckland.ac.nz/~pgut001/pubs/netscape.txt // Microsoft: http://www.cs.auckland.ac.nz/~pgut001/pubs/breakms.txt ! public byte[] GetBytes () { ! if (_algorithm == null) ! throw new CryptographicException ("No algorithm OID specified"); ! ! ASN1 encryptionAlgorithm = new ASN1 (0x30); ! encryptionAlgorithm.Add (ASN1Convert.FromOid (_algorithm)); ! ! // parameters ANY DEFINED BY algorithm OPTIONAL ! if ((_iterations > 0) || (_salt != null)) { ! ASN1 salt = new ASN1 (0x04, _salt); ! ASN1 iterations = ASN1Convert.FromInt32 (_iterations); ! ! ASN1 parameters = new ASN1 (0x30); ! parameters.Add (salt); ! parameters.Add (iterations); ! encryptionAlgorithm.Add (parameters); ! } ! ! // encapsulates EncryptedData into an OCTET STRING ! ASN1 encryptedData = new ASN1 (0x04, _data); ! ! ASN1 encryptedPrivateKeyInfo = new ASN1 (0x30); ! encryptedPrivateKeyInfo.Add (encryptionAlgorithm); ! encryptedPrivateKeyInfo.Add (encryptedData); ! ! return encryptedPrivateKeyInfo.GetBytes (); } } Index: RSAManaged.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Cryptography/RSAManaged.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RSAManaged.cs 5 Mar 2004 23:15:21 -0000 1.2 --- RSAManaged.cs 9 May 2004 12:04:34 -0000 1.3 *************** *** 3,11 **** // // Authors: ! // Sebastien Pouliot (spo...@mo...) // Ben Maurer (bm...@us...) // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) // Portions (C) 2003 Ben Maurer // // Key generation translated from Bouncy Castle JCE (http://www.bouncycastle.org/) --- 3,12 ---- // // Authors: ! // Sebastien Pouliot (seb...@xi...) // Ben Maurer (bm...@us...) // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) // Portions (C) 2003 Ben Maurer + // (C) 2004 Novell (http://www.novell.com) // // Key generation translated from Bouncy Castle JCE (http://www.bouncycastle.org/) *************** *** 33,37 **** public #endif ! class RSAManaged : RSA { private const int defaultKeySize = 1024; --- 34,38 ---- public #endif ! class RSAManaged : RSA { private const int defaultKeySize = 1024; *************** *** 50,58 **** private BigInteger e; ! public RSAManaged () : this (defaultKeySize) {} ! public RSAManaged (int dwKeySize) { ! KeySizeValue = dwKeySize; LegalKeySizesValue = new KeySizes [1]; LegalKeySizesValue [0] = new KeySizes (384, 16384, 8); --- 51,61 ---- private BigInteger e; ! public RSAManaged () : this (defaultKeySize) ! { ! } ! public RSAManaged (int keySize) { ! KeySizeValue = keySize; LegalKeySizesValue = new KeySizes [1]; LegalKeySizesValue [0] = new KeySizes (384, 16384, 8); *************** *** 75,79 **** // generate p, prime and (p-1) relatively prime to e for (;;) { ! p = BigInteger.genPseudoPrime (pbitlength); if (p % uint_e != 1) break; --- 78,82 ---- // generate p, prime and (p-1) relatively prime to e for (;;) { ! p = BigInteger.GeneratePseudoPrime (pbitlength); if (p % uint_e != 1) break; *************** *** 84,88 **** // and not equal to p for (;;) { ! q = BigInteger.genPseudoPrime (qbitlength); if ((q % uint_e != 1) && (p != q)) break; --- 87,91 ---- // and not equal to p for (;;) { ! q = BigInteger.GeneratePseudoPrime (qbitlength); if ((q % uint_e != 1) && (p != q)) break; *************** *** 91,95 **** // calculate the modulus n = p * q; ! if (n.bitCount () == KeySize) break; --- 94,98 ---- // calculate the modulus n = p * q; ! if (n.BitCount () == KeySize) break; *************** *** 105,114 **** // calculate the private exponent ! d = e.modInverse (phi); // calculate the CRT factors dp = d % pSub1; dq = d % qSub1; ! qInv = q.modInverse (p); keypairGenerated = true; --- 108,117 ---- // calculate the private exponent ! d = e.ModInverse (phi); // calculate the CRT factors dp = d % pSub1; dq = d % qSub1; ! qInv = q.ModInverse (p); keypairGenerated = true; *************** *** 116,120 **** if (KeyGenerated != null) ! KeyGenerated (this); } --- 119,123 ---- if (KeyGenerated != null) ! KeyGenerated (this, null); } *************** *** 125,129 **** // in case keypair hasn't been (yet) generated if (keypairGenerated) ! return n.bitCount (); else return base.KeySize; --- 128,132 ---- // in case keypair hasn't been (yet) generated if (keypairGenerated) ! return n.BitCount (); else return base.KeySize; *************** *** 159,165 **** if (isCRTpossible) { // m1 = c^dp mod p ! BigInteger m1 = input.modPow (dp, p); // m2 = c^dq mod q ! BigInteger m2 = input.modPow (dq, q); BigInteger h; if (m2 > m1) { --- 162,168 ---- if (isCRTpossible) { // m1 = c^dp mod p ! BigInteger m1 = input.ModPow (dp, p); // m2 = c^dq mod q ! BigInteger m2 = input.ModPow (dq, q); BigInteger h; if (m2 > m1) { *************** *** 177,183 **** else { // m = c^d mod n ! output = input.modPow (d, n); } ! byte[] result = output.getBytes (); // zeroize value input.Clear (); --- 180,186 ---- else { // m = c^d mod n ! output = input.ModPow (d, n); } ! byte[] result = output.GetBytes (); // zeroize value input.Clear (); *************** *** 195,200 **** BigInteger input = new BigInteger (rgb); ! BigInteger output = input.modPow (e, n); ! byte[] result = output.getBytes (); // zeroize value input.Clear (); --- 198,203 ---- BigInteger input = new BigInteger (rgb); ! BigInteger output = input.ModPow (e, n); ! byte[] result = output.GetBytes (); // zeroize value input.Clear (); *************** *** 212,224 **** RSAParameters param = new RSAParameters (); ! param.Exponent = e.getBytes (); ! param.Modulus = n.getBytes (); if (includePrivateParameters) { ! param.D = d.getBytes (); ! param.DP = dp.getBytes (); ! param.DQ = dq.getBytes (); ! param.InverseQ = qInv.getBytes (); ! param.P = p.getBytes (); ! param.Q = q.getBytes (); } return param; --- 215,240 ---- RSAParameters param = new RSAParameters (); ! param.Exponent = e.GetBytes (); ! param.Modulus = n.GetBytes (); if (includePrivateParameters) { ! // some parameters are required for exporting the private key ! if ((d == null) || (p == null) || (q == null)) ! throw new CryptographicException ("Missing private key"); ! param.D = d.GetBytes (); ! // hack for bugzilla #57941 where D wasn't provided ! if (param.D.Length != param.Modulus.Length) { ! byte[] normalizedD = new byte [param.Modulus.Length]; ! Buffer.BlockCopy (param.D, 0, normalizedD, (normalizedD.Length - param.D.Length), param.D.Length); ! param.D = normalizedD; ! } ! param.P = p.GetBytes (); ! param.Q = q.GetBytes (); ! // but CRT parameters are optionals ! if ((dp != null) && (dq != null) && (qInv != null)) { ! // and we include them only if we have them all ! param.DP = dp.GetBytes (); ! param.DQ = dq.GetBytes (); ! param.InverseQ = qInv.GetBytes (); ! } } return param; *************** *** 303,307 **** } ! public delegate void KeyGeneratedEventHandler (object sender); public event KeyGeneratedEventHandler KeyGenerated; --- 319,323 ---- } ! public delegate void KeyGeneratedEventHandler (object sender, EventArgs e); public event KeyGeneratedEventHandler KeyGenerated; |
From: Carlos Guzm?n ?l. <car...@us...> - 2004-05-09 12:04:14
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29860 Modified Files: ASN1.cs ASN1Convert.cs PKCS7.cs Added Files: BitConverterLE.cs Log Message: Sync Mono.Security stuff wit Mono Beta 1 sources Index: PKCS7.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security/PKCS7.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PKCS7.cs 5 Mar 2004 23:14:21 -0000 1.1 --- PKCS7.cs 9 May 2004 12:04:00 -0000 1.2 *************** *** 4,17 **** // // Author: ! // Sebastien Pouliot (spo...@mo...) // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) // - using System; using System.Collections; using System.Security.Cryptography; - //using System.Security.Cryptography.X509Certificates; using Mono.Security.X509; --- 4,16 ---- // // Author: ! // Sebastien Pouliot <seb...@xi...> // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) // using System; using System.Collections; using System.Security.Cryptography; using Mono.Security.X509; *************** *** 19,45 **** namespace Mono.Security { ! internal class PKCS7 { ! // pkcs 1 ! public const string rsaEncryption = "1.2.840.113549.1.1.1"; ! // pkcs 7 ! public const string data = "1.2.840.113549.1.7.1"; ! public const string signedData = "1.2.840.113549.1.7.2"; ! public const string envelopedData = "1.2.840.113549.1.7.3"; ! public const string signedAndEnvelopedData = "1.2.840.113549.1.7.4"; ! public const string digestedData = "1.2.840.113549.1.7.5"; ! public const string encryptedData = "1.2.840.113549.1.7.6"; ! // pkcs 9 ! public const string contentType = "1.2.840.113549.1.9.3"; ! public const string messageDigest = "1.2.840.113549.1.9.4"; ! public const string signingTime = "1.2.840.113549.1.9.5"; ! public const string countersignature = "1.2.840.113549.1.9.6"; ! public PKCS7 () {} static public ASN1 Attribute (string oid, ASN1 value) { ASN1 attr = new ASN1 (0x30); ! attr.Add (ASN1Convert.FromOID (oid)); ASN1 aset = attr.Add (new ASN1 (0x31)); aset.Add (value); --- 18,57 ---- namespace Mono.Security { ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! sealed class PKCS7 { ! public class Oid { ! // pkcs 1 ! public const string rsaEncryption = "1.2.840.113549.1.1.1"; ! // pkcs 7 ! public const string data = "1.2.840.113549.1.7.1"; ! public const string signedData = "1.2.840.113549.1.7.2"; ! public const string envelopedData = "1.2.840.113549.1.7.3"; ! public const string signedAndEnvelopedData = "1.2.840.113549.1.7.4"; ! public const string digestedData = "1.2.840.113549.1.7.5"; ! public const string encryptedData = "1.2.840.113549.1.7.6"; ! // pkcs 9 ! public const string contentType = "1.2.840.113549.1.9.3"; ! public const string messageDigest = "1.2.840.113549.1.9.4"; ! public const string signingTime = "1.2.840.113549.1.9.5"; ! public const string countersignature = "1.2.840.113549.1.9.6"; ! public Oid () ! { ! } ! } ! ! private PKCS7 () ! { ! } static public ASN1 Attribute (string oid, ASN1 value) { ASN1 attr = new ASN1 (0x30); ! attr.Add (ASN1Convert.FromOid (oid)); ASN1 aset = attr.Add (new ASN1 (0x31)); aset.Add (value); *************** *** 50,63 **** { ASN1 ai = new ASN1 (0x30); ! ai.Add (ASN1Convert.FromOID (oid)); ai.Add (new ASN1 (0x05)); // NULL return ai; } ! static public ASN1 AlgorithmIdentifier (string oid, ASN1 param) { ASN1 ai = new ASN1 (0x30); ! ai.Add (ASN1Convert.FromOID (oid)); ! ai.Add (param); return ai; } --- 62,75 ---- { ASN1 ai = new ASN1 (0x30); ! ai.Add (ASN1Convert.FromOid (oid)); ai.Add (new ASN1 (0x05)); // NULL return ai; } ! static public ASN1 AlgorithmIdentifier (string oid, ASN1 parameters) { ASN1 ai = new ASN1 (0x30); ! ai.Add (ASN1Convert.FromOid (oid)); ! ai.Add (parameters); return ai; } *************** *** 126,130 **** if (asn1[0].Tag != 0x06) throw new ArgumentException ("Invalid contentType"); ! contentType = ASN1Convert.ToOID (asn1[0]); if (asn1.Count > 1) { if (asn1[1].Tag != 0xA0) --- 138,142 ---- if (asn1[0].Tag != 0x06) throw new ArgumentException ("Invalid contentType"); ! contentType = ASN1Convert.ToOid (asn1[0]); if (asn1.Count > 1) { if (asn1[1].Tag != 0xA0) *************** *** 153,157 **** ASN1 contentInfo = new ASN1 (0x30); // contentType ContentType, -> ContentType ::= OBJECT IDENTIFIER ! contentInfo.Add (ASN1Convert.FromOID (contentType)); // content [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL if ((content != null) && (content.Count > 0)) --- 165,169 ---- ASN1 contentInfo = new ASN1 (0x30); // contentType ContentType, -> ContentType ::= OBJECT IDENTIFIER ! contentInfo.Add (ASN1Convert.FromOid (contentType)); // content [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL if ((content != null) && (content.Count > 0)) *************** *** 184,188 **** public EncryptedData (byte[] data) ! : this (new ASN1 (data)) {} public EncryptedData (ASN1 asn1) : this () --- 196,202 ---- public EncryptedData (byte[] data) ! : this (new ASN1 (data)) ! { ! } public EncryptedData (ASN1 asn1) : this () *************** *** 202,211 **** if (contentType.Tag != 0x06) throw new ArgumentException ("missing EncryptedContentInfo.ContentType"); ! _content = new ContentInfo (ASN1Convert.ToOID (contentType)); ASN1 contentEncryptionAlgorithm = encryptedContentInfo [1]; if (contentEncryptionAlgorithm.Tag != 0x30) throw new ArgumentException ("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier"); ! _encryptionAlgorithm = new ContentInfo (ASN1Convert.ToOID (contentEncryptionAlgorithm [0])); _encryptionAlgorithm.Content = contentEncryptionAlgorithm [1]; --- 216,225 ---- if (contentType.Tag != 0x06) throw new ArgumentException ("missing EncryptedContentInfo.ContentType"); ! _content = new ContentInfo (ASN1Convert.ToOid (contentType)); ASN1 contentEncryptionAlgorithm = encryptedContentInfo [1]; if (contentEncryptionAlgorithm.Tag != 0x30) throw new ArgumentException ("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier"); ! _encryptionAlgorithm = new ContentInfo (ASN1Convert.ToOid (contentEncryptionAlgorithm [0])); _encryptionAlgorithm.Content = contentEncryptionAlgorithm [1]; *************** *** 229,233 **** public byte[] EncryptedContent { ! get { return _encrypted; } } --- 243,251 ---- public byte[] EncryptedContent { ! get { ! if (_encrypted == null) ! return null; ! return (byte[]) _encrypted.Clone (); ! } } *************** *** 284,288 **** public EnvelopedData (byte[] data) ! : this (new ASN1 (data)) {} public EnvelopedData (ASN1 asn1) : this () --- 302,308 ---- public EnvelopedData (byte[] data) ! : this (new ASN1 (data)) ! { ! } public EnvelopedData (ASN1 asn1) : this () *************** *** 312,321 **** if (contentType.Tag != 0x06) throw new ArgumentException ("missing EncryptedContentInfo.ContentType"); ! _content = new ContentInfo (ASN1Convert.ToOID (contentType)); ASN1 contentEncryptionAlgorithm = encryptedContentInfo [1]; if (contentEncryptionAlgorithm.Tag != 0x30) throw new ArgumentException ("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier"); ! _encryptionAlgorithm = new ContentInfo (ASN1Convert.ToOID (contentEncryptionAlgorithm [0])); _encryptionAlgorithm.Content = contentEncryptionAlgorithm [1]; --- 332,341 ---- if (contentType.Tag != 0x06) throw new ArgumentException ("missing EncryptedContentInfo.ContentType"); ! _content = new ContentInfo (ASN1Convert.ToOid (contentType)); ASN1 contentEncryptionAlgorithm = encryptedContentInfo [1]; if (contentEncryptionAlgorithm.Tag != 0x30) throw new ArgumentException ("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier"); ! _encryptionAlgorithm = new ContentInfo (ASN1Convert.ToOid (contentEncryptionAlgorithm [0])); _encryptionAlgorithm.Content = contentEncryptionAlgorithm [1]; *************** *** 343,347 **** public byte[] EncryptedContent { ! get { return _encrypted; } } --- 363,371 ---- public byte[] EncryptedContent { ! get { ! if (_encrypted == null) ! return null; ! return (byte[]) _encrypted.Clone (); ! } } *************** *** 361,365 **** ASN1 digestAlgorithms = signedData.Add (new ASN1 (0x31)); if (hashAlgorithm != null) { ! string hashOid = CryptoConfig.MapNameToOID (hashAlgorithm); digestAlgorithms.Add (AlgorithmIdentifier (hashOid)); } --- 385,389 ---- ASN1 digestAlgorithms = signedData.Add (new ASN1 (0x31)); if (hashAlgorithm != null) { ! string hashOid = CryptoConfig.MapNameToOid (hashAlgorithm); digestAlgorithms.Add (AlgorithmIdentifier (hashOid)); } *************** *** 444,448 **** ASN1 keyEncryptionAlgorithm = data [2]; ! _oid = ASN1Convert.ToOID (keyEncryptionAlgorithm [0]); ASN1 encryptedKey = data [3]; --- 468,472 ---- ASN1 keyEncryptionAlgorithm = data [2]; ! _oid = ASN1Convert.ToOid (keyEncryptionAlgorithm [0]); ASN1 encryptedKey = data [3]; *************** *** 455,463 **** public byte[] Key { ! get { return _key; } } public byte[] SubjectKeyIdentifier { ! get { return _ski; } } --- 479,495 ---- public byte[] Key { ! get { ! if (_key == null) ! return null; ! return (byte[]) _key.Clone (); ! } } public byte[] SubjectKeyIdentifier { ! get { ! if (_ski == null) ! return null; ! return (byte[]) _ski.Clone (); ! } } *************** *** 467,471 **** public byte[] Serial { ! get { return _serial; } } --- 499,507 ---- public byte[] Serial { ! get { ! if (_serial == null) ! return null; ! return (byte[]) _serial.Clone (); ! } } *************** *** 504,508 **** public SignedData (byte[] data) ! : this (new ASN1 (data)) {} public SignedData (ASN1 asn1) --- 540,546 ---- public SignedData (byte[] data) ! : this (new ASN1 (data)) ! { ! } public SignedData (ASN1 asn1) *************** *** 552,556 **** } ! public ArrayList CRLs { get { return crls; } } --- 590,594 ---- } ! public ArrayList Crls { get { return crls; } } *************** *** 596,600 **** byte[] idcHash = ha.ComputeHash (ci[1][0].Value); ASN1 md = new ASN1 (0x30); ! mda = Attribute (messageDigest, md.Add (new ASN1 (0x04, idcHash))); signerInfo.AuthenticatedAttributes.Add (mda); } --- 634,638 ---- byte[] idcHash = ha.ComputeHash (ci[1][0].Value); ASN1 md = new ASN1 (0x30); ! mda = Attribute (Oid.messageDigest, md.Add (new ASN1 (0x04, idcHash))); signerInfo.AuthenticatedAttributes.Add (mda); } *************** *** 684,688 **** // digestAlgorithm DigestAlgorithmIdentifier ASN1 digestAlgorithm = asn1 [0][2]; ! hashAlgorithm = ASN1Convert.ToOID (digestAlgorithm [0]); // authenticatedAttributes [0] IMPLICIT Attributes OPTIONAL --- 722,726 ---- // digestAlgorithm DigestAlgorithmIdentifier ASN1 digestAlgorithm = asn1 [0][2]; ! hashAlgorithm = ASN1Convert.ToOid (digestAlgorithm [0]); // authenticatedAttributes [0] IMPLICIT Attributes OPTIONAL *************** *** 697,701 **** // digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier ASN1 digestEncryptionAlgorithm = asn1 [0][n++]; ! string digestEncryptionAlgorithmOid = ASN1Convert.ToOID (digestEncryptionAlgorithm [0]); // encryptedDigest EncryptedDigest --- 735,739 ---- // digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier ASN1 digestEncryptionAlgorithm = asn1 [0][n++]; ! string digestEncryptionAlgorithmOid = ASN1Convert.ToOid (digestEncryptionAlgorithm [0]); // encryptedDigest EncryptedDigest *************** *** 717,725 **** public byte[] SerialNumber { ! get { return (byte[]) serial.Clone (); } } public byte[] SubjectKeyIdentifier { ! get { return (byte[]) ski.Clone (); } } --- 755,771 ---- public byte[] SerialNumber { ! get { ! if (serial == null) ! return null; ! return (byte[]) serial.Clone (); ! } } public byte[] SubjectKeyIdentifier { ! get { ! if (ski == null) ! return null; ! return (byte[]) ski.Clone (); ! } } *************** *** 748,752 **** public byte[] Signature { ! get { return (byte[]) signature.Clone (); } } --- 794,802 ---- public byte[] Signature { ! get { ! if (signature == null) ! return null; ! return (byte[]) signature.Clone (); ! } } *************** *** 781,785 **** // digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier, if (key is RSA) { ! signerInfo.Add (AlgorithmIdentifier (PKCS7.rsaEncryption)); RSAPKCS1SignatureFormatter r = new RSAPKCS1SignatureFormatter (key); --- 831,835 ---- // digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier, if (key is RSA) { ! signerInfo.Add (AlgorithmIdentifier (PKCS7.Oid.rsaEncryption)); RSAPKCS1SignatureFormatter r = new RSAPKCS1SignatureFormatter (key); Index: ASN1Convert.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security/ASN1Convert.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ASN1Convert.cs 10 Feb 2004 09:42:35 -0000 1.1 --- ASN1Convert.cs 9 May 2004 12:04:00 -0000 1.2 *************** *** 2,16 **** // ASN1Convert.cs: Abstract Syntax Notation 1 convertion routines // ! // Author: ! // Sebastien Pouliot (spo...@mo...) // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) // using System; using System.Collections; using System.Security.Cryptography; using System.Text; - using System.Globalization; namespace Mono.Security { --- 2,19 ---- // ASN1Convert.cs: Abstract Syntax Notation 1 convertion routines // ! // Authors: ! // Sebastien Pouliot <seb...@xi...> ! // Jesper Pedersen <je...@it...> // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) + // (C) 2004 IT+ A/S (http://www.itplus.dk) // using System; using System.Collections; + using System.Globalization; using System.Security.Cryptography; using System.Text; namespace Mono.Security { *************** *** 20,24 **** // http://www.itu.int/ITU-T/studygroups/com17/languages/ ! internal class ASN1Convert { // RFC3280, section 4.2.1.5 --- 23,36 ---- // http://www.itu.int/ITU-T/studygroups/com17/languages/ ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! sealed class ASN1Convert { ! ! private ASN1Convert () ! { ! } // RFC3280, section 4.2.1.5 *************** *** 30,38 **** if (dt.Year < 2050) { // UTCTIME ! return new ASN1 (0x17, Encoding.ASCII.GetBytes (dt.ToString ("yyMMddHHmmss") + "Z")); } else { // GENERALIZEDTIME ! return new ASN1 (0x18, Encoding.ASCII.GetBytes (dt.ToString ("yyyyMMddHHmmss") + "Z")); } } --- 42,52 ---- if (dt.Year < 2050) { // UTCTIME ! return new ASN1 (0x17, Encoding.ASCII.GetBytes ( ! dt.ToString ("yyMMddHHmmss", CultureInfo.InvariantCulture) + "Z")); } else { // GENERALIZEDTIME ! return new ASN1 (0x18, Encoding.ASCII.GetBytes ( ! dt.ToString ("yyyyMMddHHmmss", CultureInfo.InvariantCulture) + "Z")); } } *************** *** 40,74 **** static public ASN1 FromInt32 (Int32 value) { ! byte[] integer = BitConverter.GetBytes (value); int x = 3; while (integer [x] == 0x00) x--; ASN1 asn1 = new ASN1 (0x02); ! if (x == 3) ! asn1.Value = integer; ! else { ! byte[] smallerInt = new byte [x + 1]; ! Array.Copy (integer, 0, smallerInt, 0, smallerInt.Length); ! asn1.Value = smallerInt; } return asn1; } ! static public ASN1 FromOID (string oid) { return new ASN1 (CryptoConfig.EncodeOID (oid)); } ! static public ASN1 FromUnsignedBigInteger (byte[] integer) { ! if (integer [0] == 0x00) { // this first byte is added so we're sure it's an unsigned integer // however we can't feed it into RSAParameters or DSAParameters ! int length = integer.Length + 1; byte[] uinteger = new byte [length]; ! Array.Copy (integer, 0, uinteger, 1, length); ! integer = uinteger; } ! return new ASN1 (0x02, integer); } --- 54,90 ---- static public ASN1 FromInt32 (Int32 value) { ! byte[] integer = BitConverterLE.GetBytes (value); int x = 3; while (integer [x] == 0x00) x--; ASN1 asn1 = new ASN1 (0x02); ! ! byte[] smallerInt = new byte [x + 1]; ! int index = smallerInt.Length - 1; ! for (int i = 0; i < smallerInt.Length; i++) { ! smallerInt [index] = integer [i]; ! index--; } + asn1.Value = smallerInt; + return asn1; } ! static public ASN1 FromOid (string oid) { return new ASN1 (CryptoConfig.EncodeOID (oid)); } ! static public ASN1 FromUnsignedBigInteger (byte[] big) { ! if (big [0] == 0x00) { // this first byte is added so we're sure it's an unsigned integer // however we can't feed it into RSAParameters or DSAParameters ! int length = big.Length + 1; byte[] uinteger = new byte [length]; ! Buffer.BlockCopy (big, 0, uinteger, 1, length); ! big = uinteger; } ! return new ASN1 (0x02, big); } *************** *** 85,89 **** // Convert a binary encoded OID to human readable string representation of // an OID (IETF style). Based on DUMPASN1.C from Peter Gutmann. ! static public string ToOID (ASN1 asn1) { byte[] aOID = asn1.Value; --- 101,105 ---- // Convert a binary encoded OID to human readable string representation of // an OID (IETF style). Based on DUMPASN1.C from Peter Gutmann. ! static public string ToOid (ASN1 asn1) { byte[] aOID = asn1.Value; *************** *** 97,103 **** x = 2; } ! sb.Append (x.ToString ()); sb.Append ("."); ! sb.Append (y.ToString ()); ulong val = 0; for (x = 1; x < aOID.Length; x++) { --- 113,119 ---- x = 2; } ! sb.Append (x.ToString (CultureInfo.InvariantCulture)); sb.Append ("."); ! sb.Append (y.ToString (CultureInfo.InvariantCulture)); ulong val = 0; for (x = 1; x < aOID.Length; x++) { *************** *** 105,109 **** if ( !((aOID [x] & 0x80) == 0x80)) { sb.Append ("."); ! sb.Append (val.ToString ()); val = 0; } --- 121,125 ---- if ( !((aOID [x] & 0x80) == 0x80)) { sb.Append ("."); ! sb.Append (val.ToString (CultureInfo.InvariantCulture)); val = 0; } *************** *** 123,127 **** case 13: // RFC3280: 4.1.2.5.1 UTCTime ! int year = Convert.ToInt16 (t.Substring (0, 2)); // Where YY is greater than or equal to 50, the // year SHALL be interpreted as 19YY; and --- 139,143 ---- case 13: // RFC3280: 4.1.2.5.1 UTCTime ! int year = Convert.ToInt16 (t.Substring (0, 2), CultureInfo.InvariantCulture); // Where YY is greater than or equal to 50, the // year SHALL be interpreted as 19YY; and *************** *** 138,142 **** break; } ! return DateTime.ParseExact (t, mask, CultureInfo.CurrentCulture.DateTimeFormat, DateTimeStyles.AdjustToUniversal); } } --- 154,158 ---- break; } ! return DateTime.ParseExact (t, mask, null); } } --- NEW FILE: BitConverterLE.cs --- // // Mono.Security.BitConverterLE.cs // Like System.BitConverter but always little endian // // Author: // Bernie Solomon // using System; namespace Mono.Security { internal sealed class BitConverterLE { private BitConverterLE () { } unsafe private static byte[] GetUShortBytes (byte *bytes) { if (BitConverter.IsLittleEndian) return new byte [] { bytes [0], bytes [1] }; else return new byte [] { bytes [1], bytes [0] }; } unsafe private static byte[] GetUIntBytes (byte *bytes) { if (BitConverter.IsLittleEndian) return new byte [] { bytes [0], bytes [1], bytes [2], bytes [3] }; else return new byte [] { bytes [3], bytes [2], bytes [1], bytes [0] }; } unsafe private static byte[] GetULongBytes (byte *bytes) { if (BitConverter.IsLittleEndian) return new byte [] { bytes [0], bytes [1], bytes [2], bytes [3], bytes [4], bytes [5], bytes [6], bytes [7] }; else return new byte [] { bytes [7], bytes [6], bytes [5], bytes [4], bytes [3], bytes [2], bytes [1], bytes [0] }; } unsafe internal static byte[] GetBytes (bool value) { return new byte [] { value ? (byte)1 : (byte)0 }; } unsafe internal static byte[] GetBytes (char value) { return GetUShortBytes ((byte *) &value); } unsafe internal static byte[] GetBytes (short value) { return GetUShortBytes ((byte *) &value); } unsafe internal static byte[] GetBytes (int value) { return GetUIntBytes ((byte *) &value); } unsafe internal static byte[] GetBytes (long value) { return GetULongBytes ((byte *) &value); } unsafe internal static byte[] GetBytes (ushort value) { return GetUShortBytes ((byte *) &value); } unsafe internal static byte[] GetBytes (uint value) { return GetUIntBytes ((byte *) &value); } unsafe internal static byte[] GetBytes (ulong value) { return GetULongBytes ((byte *) &value); } unsafe internal static byte[] GetBytes (float value) { return GetUIntBytes ((byte *) &value); } unsafe internal static byte[] GetBytes (double value) { return GetULongBytes ((byte *) &value); } unsafe private static void UShortFromBytes (byte *dst, byte[] src, int startIndex) { if (BitConverter.IsLittleEndian) { dst [0] = src [startIndex]; dst [1] = src [startIndex + 1]; } else { dst [0] = src [startIndex + 1]; dst [1] = src [startIndex]; } } unsafe private static void UIntFromBytes (byte *dst, byte[] src, int startIndex) { if (BitConverter.IsLittleEndian) { dst [0] = src [startIndex]; dst [1] = src [startIndex + 1]; dst [2] = src [startIndex + 2]; dst [3] = src [startIndex + 3]; } else { dst [0] = src [startIndex + 3]; dst [1] = src [startIndex + 2]; dst [2] = src [startIndex + 1]; dst [3] = src [startIndex]; } } unsafe private static void ULongFromBytes (byte *dst, byte[] src, int startIndex) { if (BitConverter.IsLittleEndian) { for (int i = 0; i < 8; ++i) dst [i] = src [startIndex + i]; } else { for (int i = 0; i < 8; ++i) dst [i] = src [startIndex + (7 - i)]; } } unsafe internal static bool ToBoolean (byte[] value, int startIndex) { return value [startIndex] != 0; } unsafe internal static char ToChar (byte[] value, int startIndex) { char ret; UShortFromBytes ((byte *) &ret, value, startIndex); return ret; } unsafe internal static short ToInt16 (byte[] value, int startIndex) { short ret; UShortFromBytes ((byte *) &ret, value, startIndex); return ret; } unsafe internal static int ToInt32 (byte[] value, int startIndex) { int ret; UIntFromBytes ((byte *) &ret, value, startIndex); return ret; } unsafe internal static long ToInt64 (byte[] value, int startIndex) { long ret; ULongFromBytes ((byte *) &ret, value, startIndex); return ret; } unsafe internal static ushort ToUInt16 (byte[] value, int startIndex) { ushort ret; UShortFromBytes ((byte *) &ret, value, startIndex); return ret; } unsafe internal static uint ToUInt32 (byte[] value, int startIndex) { uint ret; UIntFromBytes ((byte *) &ret, value, startIndex); return ret; } unsafe internal static ulong ToUInt64 (byte[] value, int startIndex) { ulong ret; ULongFromBytes ((byte *) &ret, value, startIndex); return ret; } unsafe internal static float ToSingle (byte[] value, int startIndex) { float ret; UIntFromBytes ((byte *) &ret, value, startIndex); return ret; } unsafe internal static double ToDouble (byte[] value, int startIndex) { double ret; ULongFromBytes ((byte *) &ret, value, startIndex); return ret; } } } Index: ASN1.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security/ASN1.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ASN1.cs 10 Feb 2004 09:42:35 -0000 1.1 --- ASN1.cs 9 May 2004 12:04:00 -0000 1.2 *************** *** 2,258 **** // ASN1.cs: Abstract Syntax Notation 1 - micro-parser and generator // ! // Author: ! // Sebastien Pouliot (spo...@mo...) // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) // using System; using System.Collections; namespace Mono.Security { ! // References: ! // a. ITU ASN.1 standards (free download) ! // http://www.itu.int/ITU-T/studygroups/com17/languages/ ! internal class ASN1 { ! protected byte m_nTag; ! protected byte[] m_aValue; ! protected ArrayList elist; ! public ASN1 () : this (0x00, null) {} ! public ASN1 (byte tag) : this (tag, null) {} ! public ASN1 (byte tag, byte[] data) ! { ! m_nTag = tag; ! m_aValue = data; ! } ! public ASN1 (byte[] data) ! { ! m_nTag = data [0]; ! int nLenLength = 0; ! int nLength = data [1]; ! if (nLength > 0x80) { ! // composed length ! nLenLength = nLength - 0x80; ! nLength = 0; ! for (int i = 0; i < nLenLength; i++) { ! nLength *= 256; ! nLength += data [i + 2]; } - } ! m_aValue = new byte [nLength]; ! Array.Copy (data, (2 + nLenLength), m_aValue, 0, nLength); ! if ((m_nTag & 0x20) == 0x20) { ! int nStart = (2 + nLenLength); ! Decode (data, ref nStart, data.Length); } - } ! public int Count { ! get { ! if (elist == null) ! return 0; ! return elist.Count; } - } - - public byte Tag { - get { return m_nTag; } - } ! public int Length { ! get { ! if (m_aValue != null) ! return m_aValue.Length; ! else ! return 0; } - } ! public byte[] Value { ! get { ! if (m_aValue == null) ! GetBytes (); ! return (byte[]) m_aValue.Clone (); ! } ! set { ! if (value != null) ! m_aValue = (byte[]) value.Clone (); } - } ! private bool CompareArray (byte[] array1, byte[] array2) ! { ! bool bResult = (array1.Length == array2.Length); ! if (bResult) { ! for (int i = 0; i < array1.Length; i++) { ! if (array1[i] != array2[i]) ! return false; } } - return bResult; - } ! public bool Equals (byte[] asn1) ! { ! return CompareArray (this.GetBytes (), asn1); ! } ! public bool CompareValue (byte[] aValue) ! { ! return CompareArray (m_aValue, aValue); ! } ! public virtual ASN1 Add (ASN1 asn1) ! { ! if (asn1 != null) { ! if (elist == null) ! elist = new ArrayList (); ! elist.Add (asn1); } - return asn1; - } ! public virtual byte[] GetBytes () ! { ! byte[] val = null; ! if (m_aValue != null) { ! val = m_aValue; } ! else if (Count > 0) { ! int esize = 0; ! ArrayList al = new ArrayList (); ! foreach (ASN1 a in elist) { ! byte[] item = a.GetBytes (); ! al.Add (item); ! esize += item.Length; } ! val = new byte [esize]; ! int pos = 0; ! for (int i=0; i < elist.Count; i++) { ! byte[] item = (byte[]) al[i]; ! Array.Copy (item, 0, val, pos, item.Length); ! pos += item.Length; } - } ! byte[] der; ! int nLengthLen = 0; ! if (val != null) { ! int nLength = val.Length; ! // special for length > 127 ! if (nLength > 127) { ! if (nLength < 256) { ! der = new byte [3 + nLength]; ! Array.Copy (val, 0, der, 3, nLength); ! nLengthLen += 0x81; ! der[2] = (byte)(nLength); } else { ! der = new byte [4 + nLength]; ! Array.Copy (val, 0, der, 4, nLength); ! nLengthLen += 0x82; ! der[2] = (byte)(nLength / 256); ! der[3] = (byte)(nLength % 256); } } ! else { ! der = new byte [2 + nLength]; ! Array.Copy (val, 0, der, 2, nLength); ! nLengthLen = nLength; ! } ! if (m_aValue == null) ! m_aValue = val; ! } ! else ! der = new byte[2]; ! der[0] = m_nTag; ! der[1] = (byte)nLengthLen; ! return der; ! } ! // Note: Recursive ! protected void Decode (byte[] asn1, ref int anPos, int anLength) ! { ! byte nTag; ! int nLength; ! byte[] aValue; ! // minimum is 2 bytes (tag + length of 0) ! while (anPos < anLength - 1) { ! int nPosOri = anPos; ! DecodeTLV (asn1, ref anPos, out nTag, out nLength, out aValue); ! ASN1 elm = Add (new ASN1 (nTag, aValue)); ! if ((nTag & 0x20) == 0x20) { ! int nConstructedPos = anPos; ! elm.Decode (asn1, ref nConstructedPos, nConstructedPos + nLength); } - anPos += nLength; // value length } - } ! // TLV : Tag - Length - Value ! protected void DecodeTLV (byte[] asn1, ref int anPos, out byte anTag, out int anLength, out byte[] aValue) ! { ! anTag = asn1 [anPos++]; ! anLength = asn1 [anPos++]; ! // special case where L contains the Length of the Length + 0x80 ! if ((anLength & 0x80) == 0x80) { ! int nLengthLen = anLength & 0x7F; ! anLength = 0; ! for (int i = 0; i < nLengthLen; i++) ! anLength = anLength * 256 + asn1 [anPos++]; } ! aValue = new byte [anLength]; ! Array.Copy (asn1, anPos, aValue, 0, anLength); ! } ! public ASN1 this [int index] { ! get { try { ! if (index >= elist.Count) return null; - return (ASN1) elist [index]; } ! catch { return null; } } - } ! public ASN1 Element (int index, byte anTag) ! { ! try { ! if (index >= elist.Count) ! return null; ! ASN1 elm = (ASN1) elist [index]; ! if (elm.Tag == anTag) ! return elm; ! else ! return null; } ! catch { ! return null; } } } - - } --- 2,307 ---- // ASN1.cs: Abstract Syntax Notation 1 - micro-parser and generator // ! // Authors: ! // Sebastien Pouliot <seb...@xi...> ! // Jesper Pedersen <je...@it...> // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) + // (C) 2004 Novell (http://www.novell.com) + // (C) 2004 IT+ A/S (http://www.itplus.dk) // using System; using System.Collections; + using System.IO; + using System.Text; namespace Mono.Security { ! // References: ! // a. ITU ASN.1 standards (free download) ! // http://www.itu.int/ITU-T/studygroups/com17/languages/ ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class ASN1 { ! private byte m_nTag; ! private byte[] m_aValue; ! private ArrayList elist; ! public ASN1 () : this (0x00, null) {} ! public ASN1 (byte tag) : this (tag, null) {} ! public ASN1 (byte tag, byte[] data) ! { ! m_nTag = tag; ! m_aValue = data; ! } ! public ASN1 (byte[] data) ! { ! m_nTag = data [0]; ! int nLenLength = 0; ! int nLength = data [1]; ! if (nLength > 0x80) { ! // composed length ! nLenLength = nLength - 0x80; ! nLength = 0; ! for (int i = 0; i < nLenLength; i++) { ! nLength *= 256; ! nLength += data [i + 2]; ! } } ! m_aValue = new byte [nLength]; ! Buffer.BlockCopy (data, (2 + nLenLength), m_aValue, 0, nLength); ! if ((m_nTag & 0x20) == 0x20) { ! int nStart = (2 + nLenLength); ! Decode (data, ref nStart, data.Length); ! } } ! public int Count { ! get { ! if (elist == null) ! return 0; ! return elist.Count; ! } } ! public byte Tag { ! get { return m_nTag; } } ! public int Length { ! get { ! if (m_aValue != null) ! return m_aValue.Length; ! else ! return 0; ! } } ! public byte[] Value { ! get { ! if (m_aValue == null) ! GetBytes (); ! return (byte[]) m_aValue.Clone (); ! } ! set { ! if (value != null) ! m_aValue = (byte[]) value.Clone (); } } ! private bool CompareArray (byte[] array1, byte[] array2) ! { ! bool bResult = (array1.Length == array2.Length); ! if (bResult) { ! for (int i = 0; i < array1.Length; i++) { ! if (array1[i] != array2[i]) ! return false; ! } ! } ! return bResult; ! } ! public bool Equals (byte[] asn1) ! { ! return CompareArray (this.GetBytes (), asn1); ! } ! public bool CompareValue (byte[] value) ! { ! return CompareArray (m_aValue, value); } ! public ASN1 Add (ASN1 asn1) ! { ! if (asn1 != null) { ! if (elist == null) ! elist = new ArrayList (); ! elist.Add (asn1); ! } ! return asn1; } ! ! public virtual byte[] GetBytes () ! { ! byte[] val = null; ! if (m_aValue != null) { ! val = m_aValue; } ! else if (Count > 0) { ! int esize = 0; ! ArrayList al = new ArrayList (); ! foreach (ASN1 a in elist) { ! byte[] item = a.GetBytes (); ! al.Add (item); ! esize += item.Length; ! } ! val = new byte [esize]; ! int pos = 0; ! for (int i=0; i < elist.Count; i++) { ! byte[] item = (byte[]) al[i]; ! Buffer.BlockCopy (item, 0, val, pos, item.Length); ! pos += item.Length; ! } } ! byte[] der; ! int nLengthLen = 0; ! if (val != null) { ! int nLength = val.Length; ! // special for length > 127 ! if (nLength > 127) { ! if (nLength < 256) { ! der = new byte [3 + nLength]; ! Buffer.BlockCopy (val, 0, der, 3, nLength); ! nLengthLen += 0x81; ! der[2] = (byte)(nLength); ! } ! else { ! der = new byte [4 + nLength]; ! Buffer.BlockCopy (val, 0, der, 4, nLength); ! nLengthLen += 0x82; ! der[2] = (byte)(nLength / 256); ! der[3] = (byte)(nLength % 256); ! } } else { ! der = new byte [2 + nLength]; ! Buffer.BlockCopy (val, 0, der, 2, nLength); ! nLengthLen = nLength; } + if (m_aValue == null) + m_aValue = val; } ! else ! der = new byte[2]; ! der[0] = m_nTag; ! der[1] = (byte)nLengthLen; ! return der; ! } ! // Note: Recursive ! protected void Decode (byte[] asn1, ref int anPos, int anLength) ! { ! byte nTag; ! int nLength; ! byte[] aValue; ! // minimum is 2 bytes (tag + length of 0) ! while (anPos < anLength - 1) { ! int nPosOri = anPos; ! DecodeTLV (asn1, ref anPos, out nTag, out nLength, out aValue); ! ASN1 elm = Add (new ASN1 (nTag, aValue)); ! if ((nTag & 0x20) == 0x20) { ! int nConstructedPos = anPos; ! elm.Decode (asn1, ref nConstructedPos, nConstructedPos + nLength); ! } ! anPos += nLength; // value length } } ! // TLV : Tag - Length - Value ! protected void DecodeTLV (byte[] asn1, ref int pos, out byte tag, out int length, out byte[] content) ! { ! tag = asn1 [pos++]; ! length = asn1 [pos++]; ! // special case where L contains the Length of the Length + 0x80 ! if ((length & 0x80) == 0x80) { ! int nLengthLen = length & 0x7F; ! length = 0; ! for (int i = 0; i < nLengthLen; i++) ! length = length * 256 + asn1 [pos++]; ! } ! ! content = new byte [length]; ! Buffer.BlockCopy (asn1, pos, content, 0, length); } ! public ASN1 this [int index] { ! get { ! try { ! if ((elist == null) || (index >= elist.Count)) ! return null; ! return (ASN1) elist [index]; ! } ! catch (ArgumentOutOfRangeException) { ! return null; ! } ! } ! } ! public ASN1 Element (int index, byte anTag) ! { try { ! if ((elist == null) || (index >= elist.Count)) ! return null; ! ! ASN1 elm = (ASN1) elist [index]; ! if (elm.Tag == anTag) ! return elm; ! else return null; } ! catch (ArgumentOutOfRangeException) { return null; } } ! public override string ToString() ! { ! string lineSeperator = Environment.NewLine; ! StringBuilder hexLine = new StringBuilder (); ! ! // Add tag ! hexLine.Append ("Tag: "); ! hexLine.Append (System.Convert.ToString (Tag, 16)); ! hexLine.Append (lineSeperator); ! ! // Add value ! hexLine.Append ("Value: "); ! hexLine.Append (lineSeperator); ! for (int i = 0; i < Value.Length; i++) { ! if (Value[i] < 16) { ! hexLine.Append ("0"); ! } ! hexLine.Append (System.Convert.ToString (Value [i], 16)); ! hexLine.Append (" "); ! if ((i+1) % 16 == 0) { ! hexLine.Append (lineSeperator); ! } ! } ! return hexLine.ToString (); } ! ! public void SaveToFile (string filename) ! { ! if (filename == null) ! throw new ArgumentNullException ("filename"); ! ! using (FileStream fs = File.OpenWrite (filename)) { ! byte[] data = GetBytes (); ! fs.Write (data, 0, data.Length); ! fs.Flush (); ! fs.Close (); ! } } } } |
From: Carlos Guzm?n ?l. <car...@us...> - 2004-05-09 11:59:46
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Math.Prime.Generator In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28954 Modified Files: NextPrimeFinder.cs PrimeGeneratorBase.cs SequentialSearchPrimeGeneratorBase.cs Log Message: Sync Mono.Security stuff wit Mono Beta 1 sources Index: PrimeGeneratorBase.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Math.Prime.Generator/PrimeGeneratorBase.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PrimeGeneratorBase.cs 10 Feb 2004 09:42:01 -0000 1.1 --- PrimeGeneratorBase.cs 9 May 2004 11:59:35 -0000 1.2 *************** *** 12,17 **** namespace Mono.Math.Prime.Generator { ! [CLSCompliant(false)] ! internal abstract class PrimeGeneratorBase { public virtual ConfidenceFactor Confidence { --- 12,21 ---- namespace Mono.Math.Prime.Generator { ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! abstract class PrimeGeneratorBase { public virtual ConfidenceFactor Confidence { *************** *** 27,31 **** public virtual Prime.PrimalityTest PrimalityTest { get { ! return new Prime.PrimalityTest (PrimalityTests.SmallPrimeSppTest); } } --- 31,35 ---- public virtual Prime.PrimalityTest PrimalityTest { get { ! return new Prime.PrimalityTest (PrimalityTests.RabinMillerTest); } } Index: NextPrimeFinder.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Math.Prime.Generator/NextPrimeFinder.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NextPrimeFinder.cs 10 Feb 2004 09:42:01 -0000 1.1 --- NextPrimeFinder.cs 9 May 2004 11:59:35 -0000 1.2 *************** *** 15,25 **** /// Finds the next prime after a given number. /// </summary> ! [CLSCompliant(false)] ! internal class NextPrimeFinder : SequentialSearchPrimeGeneratorBase { protected override BigInteger GenerateSearchBase (int bits, object Context) { ! if (Context == null) throw new ArgumentNullException ("Context"); BigInteger ret = new BigInteger ((BigInteger)Context); ! ret.setBit (0); return ret; } --- 15,32 ---- /// Finds the next prime after a given number. /// </summary> ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class NextPrimeFinder : SequentialSearchPrimeGeneratorBase { ! protected override BigInteger GenerateSearchBase (int bits, object Context) { ! if (Context == null) ! throw new ArgumentNullException ("Context"); ! BigInteger ret = new BigInteger ((BigInteger)Context); ! ret.SetBit (0); return ret; } Index: SequentialSearchPrimeGeneratorBase.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Math.Prime.Generator/SequentialSearchPrimeGeneratorBase.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SequentialSearchPrimeGeneratorBase.cs 10 Feb 2004 09:42:01 -0000 1.1 --- SequentialSearchPrimeGeneratorBase.cs 9 May 2004 11:59:35 -0000 1.2 *************** *** 13,23 **** namespace Mono.Math.Prime.Generator { ! [CLSCompliant(false)] ! internal class SequentialSearchPrimeGeneratorBase : PrimeGeneratorBase { ! protected virtual BigInteger GenerateSearchBase (int bits, object Context) { ! BigInteger ret = BigInteger.genRandom (bits); ! ret.setBit (0); return ret; } --- 13,27 ---- namespace Mono.Math.Prime.Generator { ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class SequentialSearchPrimeGeneratorBase : PrimeGeneratorBase { ! protected virtual BigInteger GenerateSearchBase (int bits, object context) { ! BigInteger ret = BigInteger.GenerateRandom (bits); ! ret.SetBit (0); return ret; } *************** *** 30,39 **** ! public virtual BigInteger GenerateNewPrime (int bits, object Context) { // // STEP 1. Find a place to do a sequential search // ! BigInteger curVal = GenerateSearchBase (bits, Context); const uint primeProd1 = 3u* 5u * 7u * 11u * 13u * 17u * 19u * 23u * 29u; --- 34,43 ---- ! public virtual BigInteger GenerateNewPrime (int bits, object context) { // // STEP 1. Find a place to do a sequential search // ! BigInteger curVal = GenerateSearchBase (bits, context); const uint primeProd1 = 3u* 5u * 7u * 11u * 13u * 17u * 19u * 23u * 29u; *************** *** 73,77 **** // STEP 2.3 Is the potential prime acceptable? // ! if (!IsPrimeAcceptable (curVal, Context)) goto biNotPrime; // --- 77,81 ---- // STEP 2.3 Is the potential prime acceptable? // ! if (!IsPrimeAcceptable (curVal, context)) goto biNotPrime; // *************** *** 91,95 **** } ! protected virtual bool IsPrimeAcceptable (BigInteger bi, object Context) { return true; --- 95,99 ---- } ! protected virtual bool IsPrimeAcceptable (BigInteger bi, object context) { return true; |
From: Carlos Guzm?n ?l. <car...@us...> - 2004-05-09 11:59:25
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Math.Prime In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28920 Modified Files: ConfidenceFactor.cs PrimalityTests.cs Log Message: Sync Mono.Security stuff wit Mono Beta 1 sources Index: ConfidenceFactor.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Math.Prime/ConfidenceFactor.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ConfidenceFactor.cs 10 Feb 2004 09:41:23 -0000 1.1 --- ConfidenceFactor.cs 9 May 2004 11:59:12 -0000 1.2 *************** *** 14,18 **** /// A factor of confidence. /// </summary> ! internal enum ConfidenceFactor { /// <summary> /// Only suitable for development use, probability of failure may be greater than 1/2^20. --- 14,23 ---- /// A factor of confidence. /// </summary> ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! enum ConfidenceFactor { /// <summary> /// Only suitable for development use, probability of failure may be greater than 1/2^20. Index: PrimalityTests.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Math.Prime/PrimalityTests.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PrimalityTests.cs 10 Feb 2004 09:41:23 -0000 1.1 --- PrimalityTests.cs 9 May 2004 11:59:12 -0000 1.2 *************** *** 9,21 **** using System; - using System.Security.Cryptography; namespace Mono.Math.Prime { ! [CLSCompliant(false)] ! internal delegate bool PrimalityTest (BigInteger bi, ConfidenceFactor confidence); ! [CLSCompliant(false)] ! internal sealed class PrimalityTests { #region SPP Test --- 9,32 ---- using System; namespace Mono.Math.Prime { ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! delegate bool PrimalityTest (BigInteger bi, ConfidenceFactor confidence); ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! sealed class PrimalityTests { ! ! private PrimalityTests () ! { ! } #region SPP Test *************** *** 23,27 **** private static int GetSPPRounds (BigInteger bi, ConfidenceFactor confidence) { ! int bc = bi.bitCount(); int Rounds; --- 34,38 ---- private static int GetSPPRounds (BigInteger bi, ConfidenceFactor confidence) { ! int bc = bi.BitCount(); int Rounds; *************** *** 93,104 **** BigInteger t = p_sub1 >> s; ! int bits = bi.bitCount (); BigInteger a = null; - RandomNumberGenerator rng = RandomNumberGenerator.Create (); BigInteger.ModulusRing mr = new BigInteger.ModulusRing (bi); for (int round = 0; round < Rounds; round++) { while (true) { // generate a < n ! a = BigInteger.genRandom (bits, rng); // make sure "a" is not 0 --- 104,114 ---- BigInteger t = p_sub1 >> s; ! int bits = bi.BitCount (); BigInteger a = null; BigInteger.ModulusRing mr = new BigInteger.ModulusRing (bi); for (int round = 0; round < Rounds; round++) { while (true) { // generate a < n ! a = BigInteger.GenerateRandom (bits); // make sure "a" is not 0 *************** *** 107,111 **** } ! if (a.gcd (bi) != 1) return false; BigInteger b = mr.Pow (a, t); --- 117,121 ---- } ! if (a.GCD (bi) != 1) return false; BigInteger b = mr.Pow (a, t); *************** *** 169,173 **** #endregion - // TODO: Implement the Lucus test // TODO: Implement other new primality tests --- 179,182 ---- |
From: Carlos Guzm?n ?l. <car...@us...> - 2004-05-09 11:59:06
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Math In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28829 Modified Files: BigInteger.cs Log Message: Sync Mono.Security stuff wit Mono Beta 1 sources Index: BigInteger.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Math/BigInteger.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BigInteger.cs 10 Feb 2004 09:40:51 -0000 1.1 --- BigInteger.cs 9 May 2004 11:58:48 -0000 1.2 *************** *** 1,3 **** ! // // BigInteger.cs - Big Integer implementation // --- 1,3 ---- ! // // BigInteger.cs - Big Integer implementation // *************** *** 5,9 **** // Ben Maurer // Chew Keong TAN ! // Sebastien Pouliot (spo...@mo...) // // Copyright (c) 2003 Ben Maurer --- 5,10 ---- // Ben Maurer // Chew Keong TAN ! // Sebastien Pouliot <seb...@xi...> ! // Pieter Philippaerts <Pi...@me...> // // Copyright (c) 2003 Ben Maurer *************** *** 20,25 **** namespace Mono.Math { ! [CLSCompliant(false)] ! internal class BigInteger { #region Data Storage --- 21,30 ---- namespace Mono.Math { ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! class BigInteger { #region Data Storage *************** *** 58,62 **** /// </para> /// </remarks> ! public static readonly uint [] smallPrimes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, --- 63,67 ---- /// </para> /// </remarks> ! internal static uint [] smallPrimes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, *************** *** 146,149 **** --- 151,155 ---- } + [CLSCompliant (false)] public BigInteger (Sign sign, uint len) { *************** *** 158,161 **** --- 164,168 ---- } + [CLSCompliant (false)] public BigInteger (BigInteger bi, uint len) { *************** *** 188,192 **** (inData [i-2] << (2*8)) | (inData [i-1] << (1*8)) | ! (inData [i-0] << (0*8)) ); } --- 195,199 ---- (inData [i-2] << (2*8)) | (inData [i-1] << (1*8)) | ! (inData [i]) ); } *************** *** 201,204 **** --- 208,212 ---- } + [CLSCompliant (false)] public BigInteger (uint [] inData) { *************** *** 213,216 **** --- 221,225 ---- } + [CLSCompliant (false)] public BigInteger (uint ui) { *************** *** 218,221 **** --- 227,231 ---- } + [CLSCompliant (false)] public BigInteger (ulong ul) { *************** *** 226,229 **** --- 236,240 ---- } + [CLSCompliant (false)] public static implicit operator BigInteger (uint value) { *************** *** 237,240 **** --- 248,252 ---- } + [CLSCompliant (false)] public static implicit operator BigInteger (ulong value) { *************** *** 242,245 **** --- 254,302 ---- } + /* This is the BigInteger.Parse method I use. This method works + because BigInteger.ToString returns the input I gave to Parse. */ + public static BigInteger Parse (string number) + { + if (number == null) + throw new ArgumentNullException ("number"); + + int i = 0, len = number.Length; + char c; + bool digits_seen = false; + BigInteger val = new BigInteger (0); + if (number [i] == '+') { + i++; + } + else if (number [i] == '-') { + throw new FormatException (WouldReturnNegVal); + } + + for (; i < len; i++) { + c = number [i]; + if (c == '\0') { + i = len; + continue; + } + if (c >= '0' && c <= '9') { + val = val * 10 + (c - '0'); + digits_seen = true; + } + else { + if (Char.IsWhiteSpace (c)) { + for (i++; i < len; i++) { + if (!Char.IsWhiteSpace (number [i])) + throw new FormatException (); + } + break; + } + else + throw new FormatException (); + } + } + if (!digits_seen) + throw new FormatException (); + return val; + } + #endregion *************** *** 287,290 **** --- 344,348 ---- } + [CLSCompliant (false)] public static uint operator % (BigInteger bi, uint ui) { *************** *** 349,352 **** --- 407,462 ---- #endregion + #region Friendly names for operators + + // with names suggested by FxCop 1.30 + + public static BigInteger Add (BigInteger bi1, BigInteger bi2) + { + return (bi1 + bi2); + } + + public static BigInteger Subtract (BigInteger bi1, BigInteger bi2) + { + return (bi1 - bi2); + } + + public static int Modulus (BigInteger bi, int i) + { + return (bi % i); + } + + [CLSCompliant (false)] + public static uint Modulus (BigInteger bi, uint ui) + { + return (bi % ui); + } + + public static BigInteger Modulus (BigInteger bi1, BigInteger bi2) + { + return (bi1 % bi2); + } + + public static BigInteger Divid (BigInteger bi, int i) + { + return (bi / i); + } + + public static BigInteger Divid (BigInteger bi1, BigInteger bi2) + { + return (bi1 / bi2); + } + + public static BigInteger Multiply (BigInteger bi1, BigInteger bi2) + { + return (bi1 * bi2); + } + + public static BigInteger Multiply (BigInteger bi, int i) + { + return (bi * i); + } + + #endregion + #region Random private static RandomNumberGenerator rng; *************** *** 365,369 **** /// <param name="rng">A random number generator to use to obtain the bits.</param> /// <returns>A random number of the specified length.</returns> ! public static BigInteger genRandom (int bits, RandomNumberGenerator rng) { int dwords = bits >> 5; --- 475,479 ---- /// <param name="rng">A random number generator to use to obtain the bits.</param> /// <returns>A random number of the specified length.</returns> ! public static BigInteger GenerateRandom (int bits, RandomNumberGenerator rng) { int dwords = bits >> 5; *************** *** 398,404 **** /// <param name="bits">The number of bits for the new number.</param> /// <returns>A random number of the specified length.</returns> ! public static BigInteger genRandom (int bits) { ! return genRandom (bits, Rng); } --- 508,514 ---- /// <param name="bits">The number of bits for the new number.</param> /// <returns>A random number of the specified length.</returns> ! public static BigInteger GenerateRandom (int bits) { ! return GenerateRandom (bits, Rng); } *************** *** 407,413 **** /// </summary> /// <param name="rng">A RNG.</param> ! public void randomize (RandomNumberGenerator rng) { ! int bits = this.bitCount (); int dwords = bits >> 5; int remBits = bits & 0x1F; --- 517,523 ---- /// </summary> /// <param name="rng">A RNG.</param> ! public void Randomize (RandomNumberGenerator rng) { ! int bits = this.BitCount (); int dwords = bits >> 5; int remBits = bits & 0x1F; *************** *** 438,444 **** /// Randomizes the bits in "this" from the default RNG. /// </summary> ! public void randomize () { ! randomize (Rng); } --- 548,554 ---- /// Randomizes the bits in "this" from the default RNG. /// </summary> ! public void Randomize () { ! Randomize (Rng); } *************** *** 447,451 **** #region Bitwise ! public int bitCount () { this.Normalize (); --- 557,561 ---- #region Bitwise ! public int BitCount () { this.Normalize (); *************** *** 469,473 **** /// <param name="bitNum">The bit to test. The least significant bit is 0.</param> /// <returns>True if bitNum is set to 1, else false.</returns> ! public bool testBit (uint bitNum) { uint bytePos = bitNum >> 5; // divide by 32 --- 579,584 ---- /// <param name="bitNum">The bit to test. The least significant bit is 0.</param> /// <returns>True if bitNum is set to 1, else false.</returns> ! [CLSCompliant (false)] ! public bool TestBit (uint bitNum) { uint bytePos = bitNum >> 5; // divide by 32 *************** *** 478,482 **** } ! public bool testBit (int bitNum) { if (bitNum < 0) throw new IndexOutOfRangeException ("bitNum out of range"); --- 589,593 ---- } ! public bool TestBit (int bitNum) { if (bitNum < 0) throw new IndexOutOfRangeException ("bitNum out of range"); *************** *** 489,502 **** } ! public void setBit (uint bitNum) { ! setBit (bitNum, true); } ! public void clearBit (uint bitNum) { ! setBit (bitNum, false); } ! public void setBit (uint bitNum, bool val) { uint bytePos = bitNum >> 5; // divide by 32 --- 600,617 ---- } ! [CLSCompliant (false)] ! public void SetBit (uint bitNum) { ! SetBit (bitNum, true); } ! ! [CLSCompliant (false)] ! public void ClearBit (uint bitNum) { ! SetBit (bitNum, false); } ! [CLSCompliant (false)] ! public void SetBit (uint bitNum, bool value) { uint bytePos = bitNum >> 5; // divide by 32 *************** *** 504,508 **** if (bytePos < this.length) { uint mask = (uint)1 << (int)(bitNum & 0x1F); ! if (val) this.data [bytePos] |= mask; else --- 619,623 ---- if (bytePos < this.length) { uint mask = (uint)1 << (int)(bitNum & 0x1F); ! if (value) this.data [bytePos] |= mask; else *************** *** 515,527 **** if (this == 0) return -1; int i = 0; ! while (!testBit (i)) i++; return i; } ! public byte [] getBytes () { if (this == 0) return new byte [1]; ! int numBits = bitCount (); int numBytes = numBits >> 3; if ((numBits & 0x7) != 0) --- 630,642 ---- if (this == 0) return -1; int i = 0; ! while (!TestBit (i)) i++; return i; } ! public byte[] GetBytes () { if (this == 0) return new byte [1]; ! int numBits = BitCount (); int numBytes = numBits >> 3; if ((numBits & 0x7) != 0) *************** *** 550,553 **** --- 665,669 ---- #region Compare + [CLSCompliant (false)] public static bool operator == (BigInteger bi1, uint ui) { *************** *** 556,559 **** --- 672,676 ---- } + [CLSCompliant (false)] public static bool operator != (BigInteger bi1, uint ui) { *************** *** 611,614 **** --- 728,732 ---- #region Formatting + [CLSCompliant (false)] public string ToString (uint radix) { *************** *** 616,623 **** } ! public string ToString (uint radix, string charSet) { ! if (charSet.Length < radix) ! throw new ArgumentException ("charSet length less than radix", "charSet"); if (radix == 1) throw new ArgumentException ("There is no such thing as radix one notation", "radix"); --- 734,742 ---- } ! [CLSCompliant (false)] ! public string ToString (uint radix, string characterSet) { ! if (characterSet.Length < radix) ! throw new ArgumentException ("charSet length less than radix", "characterSet"); if (radix == 1) throw new ArgumentException ("There is no such thing as radix one notation", "radix"); *************** *** 632,636 **** while (a != 0) { uint rem = Kernel.SingleByteDivideInPlace (a, radix); ! result = charSet [ (int)rem] + result; } --- 751,755 ---- while (a != 0) { uint rem = Kernel.SingleByteDivideInPlace (a, radix); ! result = characterSet [(int) rem] + result; } *************** *** 694,708 **** #region Number Theory ! public BigInteger gcd (BigInteger bi) { return Kernel.gcd (this, bi); } ! public BigInteger modInverse (BigInteger mod) { ! return Kernel.modInverse (this, mod); } ! public BigInteger modPow (BigInteger exp, BigInteger n) { ModulusRing mr = new ModulusRing (n); --- 813,827 ---- #region Number Theory ! public BigInteger GCD (BigInteger bi) { return Kernel.gcd (this, bi); } ! public BigInteger ModInverse (BigInteger modulus) { ! return Kernel.modInverse (this, modulus); } ! public BigInteger ModPow (BigInteger exp, BigInteger n) { ModulusRing mr = new ModulusRing (n); *************** *** 714,740 **** #region Prime Testing ! public bool isProbablePrime () ! { ! ! for (int p = 0; p < smallPrimes.Length; p++) { ! if (this % smallPrimes [p] == 0) ! return this == smallPrimes [p]; ! } ! ! return ! PrimalityTests.SmallPrimeSppTest (this, Prime.ConfidenceFactor.Medium); ! } ! ! [Obsolete] ! public bool isProbablePrime (int notUsed) { - for (int p = 0; p < smallPrimes.Length; p++) { if (this % smallPrimes [p] == 0) ! return this == smallPrimes [p]; } ! ! return ! PrimalityTests.SmallPrimeSppTest (this, Prime.ConfidenceFactor.Medium); } --- 833,845 ---- #region Prime Testing ! public bool IsProbablePrime () { for (int p = 0; p < smallPrimes.Length; p++) { + if (this == smallPrimes [p]) + return true; if (this % smallPrimes [p] == 0) ! return false; } ! return PrimalityTests.RabinMillerTest (this, Prime.ConfidenceFactor.Medium); } *************** *** 748,752 **** /// <param name="bi">A BigInteger</param> /// <returns>The smallest prime >= bi. More mathematically, if bi is prime: bi, else Prime [PrimePi [bi] + 1].</returns> ! public static BigInteger NextHightestPrime (BigInteger bi) { NextPrimeFinder npf = new NextPrimeFinder (); --- 853,857 ---- /// <param name="bi">A BigInteger</param> /// <returns>The smallest prime >= bi. More mathematically, if bi is prime: bi, else Prime [PrimePi [bi] + 1].</returns> ! public static BigInteger NextHighestPrime (BigInteger bi) { NextPrimeFinder npf = new NextPrimeFinder (); *************** *** 754,758 **** } ! public static BigInteger genPseudoPrime (int bits) { SequentialSearchPrimeGeneratorBase sspg = new SequentialSearchPrimeGeneratorBase (); --- 859,863 ---- } ! public static BigInteger GeneratePseudoPrime (int bits) { SequentialSearchPrimeGeneratorBase sspg = new SequentialSearchPrimeGeneratorBase (); *************** *** 787,797 **** #endregion ! public sealed class ModulusRing { BigInteger mod, constant; ! public ModulusRing (BigInteger mod) { ! this.mod = mod; // calculate constant = b^ (2k) / m --- 892,907 ---- #endregion ! #if INSIDE_CORLIB ! internal ! #else ! public ! #endif ! sealed class ModulusRing { BigInteger mod, constant; ! public ModulusRing (BigInteger modulus) { ! this.mod = modulus; // calculate constant = b^ (2k) / m *************** *** 919,923 **** BigInteger tempNum = new BigInteger (b % mod, mod.length << 1); // ensures (tempNum * tempNum) < b^ (2k) ! uint totalBits = (uint)exp.bitCount (); uint [] wkspace = new uint [mod.length << 1]; --- 1029,1033 ---- BigInteger tempNum = new BigInteger (b % mod, mod.length << 1); // ensures (tempNum * tempNum) < b^ (2k) ! uint totalBits = (uint)exp.BitCount (); uint [] wkspace = new uint [mod.length << 1]; *************** *** 925,929 **** // perform squaring and multiply exponentiation for (uint pos = 0; pos < totalBits; pos++) { ! if (exp.testBit (pos)) { Array.Clear (wkspace, 0, wkspace.Length); --- 1035,1039 ---- // perform squaring and multiply exponentiation for (uint pos = 0; pos < totalBits; pos++) { ! if (exp.TestBit (pos)) { Array.Clear (wkspace, 0, wkspace.Length); *************** *** 953,957 **** BigInteger tempNum = new BigInteger (Montgomery.ToMont (b, mod), mod.length << 1); // ensures (tempNum * tempNum) < b^ (2k) uint mPrime = Montgomery.Inverse (mod.data [0]); ! uint totalBits = (uint)exp.bitCount (); uint [] wkspace = new uint [mod.length << 1]; --- 1063,1067 ---- BigInteger tempNum = new BigInteger (Montgomery.ToMont (b, mod), mod.length << 1); // ensures (tempNum * tempNum) < b^ (2k) uint mPrime = Montgomery.Inverse (mod.data [0]); ! uint totalBits = (uint)exp.BitCount (); uint [] wkspace = new uint [mod.length << 1]; *************** *** 959,963 **** // perform squaring and multiply exponentiation for (uint pos = 0; pos < totalBits; pos++) { ! if (exp.testBit (pos)) { Array.Clear (wkspace, 0, wkspace.Length); --- 1069,1073 ---- // perform squaring and multiply exponentiation for (uint pos = 0; pos < totalBits; pos++) { ! if (exp.TestBit (pos)) { Array.Clear (wkspace, 0, wkspace.Length); *************** *** 983,986 **** --- 1093,1097 ---- // TODO: Make tests for this, not really needed b/c prime stuff // checks it, but still would be nice + [CLSCompliant (false)] public BigInteger Pow (uint b, BigInteger exp) { *************** *** 994,997 **** --- 1105,1109 ---- } + [CLSCompliant (false)] private unsafe BigInteger OddPow (uint b, BigInteger exp) { *************** *** 1004,1008 **** uint mPrime = Montgomery.Inverse (mod.data [0]); ! uint pos = (uint)exp.bitCount () - 2; // --- 1116,1120 ---- uint mPrime = Montgomery.Inverse (mod.data [0]); ! uint pos = (uint)exp.BitCount () - 2; // *************** *** 1017,1021 **** resultNum = Montgomery.Reduce (resultNum, mod, mPrime); ! if (exp.testBit (pos)) { // --- 1129,1133 ---- resultNum = Montgomery.Reduce (resultNum, mod, mPrime); ! if (exp.TestBit (pos)) { // *************** *** 1104,1108 **** BigInteger resultNum = new BigInteger ((BigInteger)b, mod.length << 1 + 1); ! uint pos = (uint)exp.bitCount () - 2; // --- 1216,1220 ---- BigInteger resultNum = new BigInteger ((BigInteger)b, mod.length << 1 + 1); ! uint pos = (uint)exp.BitCount () - 2; // *************** *** 1118,1122 **** BarrettReduction (resultNum); ! if (exp.testBit (pos)) { // --- 1230,1234 ---- BarrettReduction (resultNum); ! if (exp.TestBit (pos)) { // *************** *** 1282,1286 **** // TODO: eat small bits, the ones we can do with no modular reduction // ! uint pos = (uint)exp.bitCount () - 2; do { --- 1394,1398 ---- // TODO: eat small bits, the ones we can do with no modular reduction // ! uint pos = (uint)exp.BitCount () - 2; do { *************** *** 1288,1292 **** resultNum = Montgomery.Reduce (resultNum, mod, mPrime); ! if (exp.testBit (pos)) { // // resultNum = (resultNum * 2) % mod --- 1400,1404 ---- resultNum = Montgomery.Reduce (resultNum, mod, mPrime); ! if (exp.TestBit (pos)) { // // resultNum = (resultNum * 2) % mod *************** *** 1333,1337 **** } ! public sealed class Montgomery { public static uint Inverse (uint n) { --- 1445,1455 ---- } ! internal sealed class Montgomery { ! ! private Montgomery () ! { ! } ! ! [CLSCompliant (false)] public static uint Inverse (uint n) { *************** *** 1353,1356 **** --- 1471,1475 ---- } + [CLSCompliant (false)] public static unsafe BigInteger Reduce (BigInteger n, BigInteger m, uint mPrime) { *************** *** 1372,1376 **** uint* mP = mm, aSP = a, aDP = a; ! ulong c = (ulong)u_i * (ulong)*(mP++) + *(aSP++); c >>= 32; uint j = 1; --- 1491,1495 ---- uint* mP = mm, aSP = a, aDP = a; ! ulong c = (ulong)u_i * ((ulong)*(mP++)) + *(aSP++); c >>= 32; uint j = 1; *************** *** 1406,1414 **** return A; } ! public static BigInteger Reduce (BigInteger n, BigInteger m) { return Reduce (n, m, Inverse (m.data [0])); } } --- 1525,1534 ---- return A; } ! #if _NOT_USED_ public static BigInteger Reduce (BigInteger n, BigInteger m) { return Reduce (n, m, Inverse (m.data [0])); } + #endif } *************** *** 2079,2083 **** // Keep adding until no carry ! while ((*tP3++) == 0x0) (*tP3)++; } --- 2199,2203 ---- // Keep adding until no carry ! while ((*tP3++) == 0) (*tP3)++; } *************** *** 2093,2097 **** } ! public static bool Double (uint [] u, int l) { uint x, carry = 0; --- 2213,2219 ---- } ! /* ! * Never called in BigInteger (and part of a private class) ! * public static bool Double (uint [] u, int l) { uint x, carry = 0; *************** *** 2105,2109 **** if (carry != 0) u [l] = carry; return carry != 0; ! } #endregion --- 2227,2231 ---- if (carry != 0) u [l] = carry; return carry != 0; ! }*/ #endregion |
From: Carlos Guzm?n ?l. <car...@us...> - 2004-05-06 08:17:47
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32093 Modified Files: changelog.txt Log Message: 2004-05-06 Carlos Guzman Alvarez <car...@te...> * PostgreSql/Data/PgSqlClient/NPgClient/PgDbClient.cs: - Changes for patch (#948340) ( Disable the nagle algorithm on socket setup ) Index: changelog.txt =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/changelog.txt,v retrieving revision 1.115 retrieving revision 1.116 diff -C2 -d -r1.115 -r1.116 *** changelog.txt 3 May 2004 20:31:25 -0000 1.115 --- changelog.txt 6 May 2004 08:17:39 -0000 1.116 *************** *** 2,5 **** --- 2,14 ---- ------------------------------------------------------- + + 2004-05-06 Carlos Guzman Alvarez <car...@te...> + + * PostgreSql/Data/PgSqlClient/NPgClient/PgDbClient.cs: + + - Changes for patch (#948340) + ( Disable the nagle algorithm on socket setup ) + + 2004-05-03 Carlos Guzman Alvarez <car...@te...> |