pgsqlclient-checkins Mailing List for PostgreSqlClient (Page 27)
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: <car...@us...> - 2004-02-09 10:47:21
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3419 Removed Files: TlsAbstractCipherSuite.cs Log Message: removed old files --- TlsAbstractCipherSuite.cs DELETED --- |
|
From: <car...@us...> - 2004-02-09 10:46:39
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3263 Removed Files: TlsCompressionMethod.cs Log Message: removed old files --- TlsCompressionMethod.cs DELETED --- |
|
From: <car...@us...> - 2004-02-09 10:45:53
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3056 Removed Files: TlsNetworkStream.cs TlsProtocol.cs TlsSession.cs TlsSessionContext.cs TlsSessionSettings.cs TlsSessionState.cs TlsSocket.cs Log Message: removed old files --- TlsNetworkStream.cs DELETED --- --- TlsProtocol.cs DELETED --- --- TlsSession.cs DELETED --- --- TlsSessionContext.cs DELETED --- --- TlsSessionSettings.cs DELETED --- --- TlsSessionState.cs DELETED --- --- TlsSocket.cs DELETED --- |
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls.Handshake/Mono.Security.Protocol.Tls.Handshake.Client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29105 Modified Files: TlsClientCertificate.cs TlsClientCertificateVerify.cs Log Message: Updated files Index: TlsClientCertificate.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls.Handshake/Mono.Security.Protocol.Tls.Handshake.Client/TlsClientCertificate.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TlsClientCertificate.cs 21 Dec 2003 14:56:06 -0000 1.13 --- TlsClientCertificate.cs 8 Feb 2004 22:26:17 -0000 1.14 *************** *** 1,93 **** ! /* Transport Security Layer (TLS) ! * Copyright (c) 2003 Carlos Guzmán Álvarez ! * ! * Permission is hereby granted, free of charge, to any person ! * obtaining a copy of this software and associated documentation ! * files (the "Software"), to deal in the Software without restriction, ! * including without limitation the rights to use, copy, modify, merge, ! * publish, distribute, sublicense, and/or sell copies of the Software, ! * and to permit persons to whom the Software is furnished to do so, ! * subject to the following conditions: ! * ! * The above copyright notice and this permission notice shall be included ! * in all copies or substantial portions of the Software. ! * ! * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ! * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES ! * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ! * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT ! * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, ! * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ! * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ! * DEALINGS IN THE SOFTWARE. ! */ ! ! using System; ! using System.Security.Cryptography.X509Certificates; ! ! using Mono.Security.Protocol.Tls; ! ! namespace Mono.Security.Protocol.Tls.Handshake.Client ! { ! internal class TlsClientCertificate : TlsHandshakeMessage ! { ! #region Constructors ! ! public TlsClientCertificate(TlsContext context) ! : base(context, TlsHandshakeType.Certificate) ! { ! } ! ! #endregion ! ! #region Methods ! ! public override void Update() ! { ! base.Update(); ! this.Reset(); ! } ! ! #endregion ! ! #region Protected Methods ! ! protected override void ProcessAsSsl3() ! { ! this.ProcessAsTls1(); ! } ! ! protected override void ProcessAsTls1() ! { ! if (this.Context.ClientSettings.Certificates == null || ! this.Context.ClientSettings.Certificates.Count == 0) ! { ! throw this.Context.CreateException("Client certificate requested by the server and no client certificate specified."); ! } ! ! // Select a valid certificate ! X509Certificate clientCert = this.Context.ClientSettings.Certificates[0]; ! ! /* ! clientCert = this.Context.SslStream.RaiseClientCertificateSelection( ! this.Context.ClientSettings.Certificates, ! this.Context.ServerSettings.Certificates[0], ! this.Context.ClientSettings.TargetHost, ! null); ! */ ! ! ! // Write client certificates information to a stream ! TlsStream stream = new TlsStream(); ! ! stream.WriteInt24(clientCert.GetRawCertData().Length); ! stream.Write(clientCert.GetRawCertData()); ! ! // Compose the message ! this.WriteInt24((int)stream.Length); ! this.Write(stream.ToArray()); ! } ! ! #endregion ! } ! } --- 1,94 ---- ! /* Transport Security Layer (TLS) ! * Copyright (c) 2003 Carlos Guzmán Álvarez ! * ! * Permission is hereby granted, free of charge, to any person ! * obtaining a copy of this software and associated documentation ! * files (the "Software"), to deal in the Software without restriction, ! * including without limitation the rights to use, copy, modify, merge, ! * publish, distribute, sublicense, and/or sell copies of the Software, ! * and to permit persons to whom the Software is furnished to do so, ! * subject to the following conditions: ! * ! * The above copyright notice and this permission notice shall be included ! * in all copies or substantial portions of the Software. ! * ! * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ! * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES ! * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ! * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT ! * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, ! * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ! * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ! * DEALINGS IN THE SOFTWARE. ! */ ! ! using System; ! using System.Security.Cryptography.X509Certificates; ! ! using Mono.Security.Protocol.Tls; ! ! namespace Mono.Security.Protocol.Tls.Handshake.Client ! { ! internal class TlsClientCertificate : TlsHandshakeMessage ! { ! #region Constructors ! ! public TlsClientCertificate(TlsContext context) ! : base(context, TlsHandshakeType.Certificate) ! { ! } ! ! #endregion ! ! #region Methods ! ! public override void Update() ! { ! base.Update(); ! this.Reset(); ! } ! ! #endregion ! ! #region Protected Methods ! ! protected override void ProcessAsSsl3() ! { ! this.ProcessAsTls1(); ! } ! ! protected override void ProcessAsTls1() ! { ! if (this.Context.ClientSettings.Certificates == null || ! this.Context.ClientSettings.Certificates.Count == 0) ! { ! throw this.Context.CreateException("Client certificate requested by the server and no client certificate specified."); ! } ! ! // Select a valid certificate ! X509Certificate clientCert = this.Context.ClientSettings.Certificates[0]; ! ! /* ! clientCert = this.Context.SslStream.RaiseClientCertificateSelection( ! this.Context.ClientSettings.Certificates, ! this.Context.ServerSettings.Certificates[0], ! this.Context.ClientSettings.TargetHost, ! null); ! */ ! ! this.Context.ClientSettings.ClientCertificate = clientCert; ! ! // Write client certificates information to a stream ! TlsStream stream = new TlsStream(); ! ! stream.WriteInt24(clientCert.GetRawCertData().Length); ! stream.Write(clientCert.GetRawCertData()); ! ! // Compose the message ! this.WriteInt24((int)stream.Length); ! this.Write(stream.ToArray()); ! } ! ! #endregion ! } ! } Index: TlsClientCertificateVerify.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls.Handshake/Mono.Security.Protocol.Tls.Handshake.Client/TlsClientCertificateVerify.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** TlsClientCertificateVerify.cs 26 Dec 2003 11:17:14 -0000 1.17 --- TlsClientCertificateVerify.cs 8 Feb 2004 22:26:17 -0000 1.18 *************** *** 1,125 **** ! /* Transport Security Layer (TLS) ! * Copyright (c) 2003 Carlos Guzmán Álvarez ! * ! * Permission is hereby granted, free of charge, to any person ! * obtaining a copy of this software and associated documentation ! * files (the "Software"), to deal in the Software without restriction, ! * including without limitation the rights to use, copy, modify, merge, ! * publish, distribute, sublicense, and/or sell copies of the Software, ! * and to permit persons to whom the Software is furnished to do so, ! * subject to the following conditions: ! * ! * The above copyright notice and this permission notice shall be included ! * in all copies or substantial portions of the Software. ! * ! * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ! * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES ! * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ! * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT ! * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, ! * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ! * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ! * DEALINGS IN THE SOFTWARE. ! */ ! ! using System; ! using System.Security.Cryptography.X509Certificates; ! ! using System.Security.Cryptography; ! using Mono.Security.Cryptography; ! ! namespace Mono.Security.Protocol.Tls.Handshake.Client ! { ! internal class TlsClientCertificateVerify : TlsHandshakeMessage ! { ! #region Constructors ! ! public TlsClientCertificateVerify(TlsContext context) ! : base(context, TlsHandshakeType.Finished) ! { ! } ! ! #endregion ! ! #region Methods ! ! public override void Update() ! { ! base.Update(); ! this.Reset(); ! } ! ! #endregion ! ! #region Protected Methods ! ! protected override void ProcessAsSsl3() ! { ! throw new NotSupportedException(); ! } ! ! protected override void ProcessAsTls1() ! { ! // Compute handshake messages hash ! MD5SHA1 hash = new MD5SHA1(); ! hash.ComputeHash( ! this.Context.HandshakeMessages.ToArray(), ! 0, ! (int)this.Context.HandshakeMessages.Length); ! ! // RSAManaged of the selected ClientCertificate ! // (at this moment the first one) ! RSA rsa = getClientCertRSA(); ! ! // Write message ! Write(hash.CreateSignature(rsa)); ! } ! ! #endregion ! ! #region Private methods ! ! private RSA getClientCertRSA() ! { ! RSAParameters rsaParams = new RSAParameters(); ! // for RSA m_publickey contains 2 ASN.1 integers ! // the modulus and the public exponent ! ASN1 pubkey = new ASN1 (this.Context.ClientSettings.Certificates[0].GetPublicKey()); ! ASN1 modulus = pubkey [0]; ! if ((modulus == null) || (modulus.Tag != 0x02)) ! return null; ! ASN1 exponent = pubkey [1]; ! if (exponent.Tag != 0x02) ! return null; ! ! rsaParams.Modulus = this.getUnsignedBigInteger(modulus.Value); ! rsaParams.Exponent = exponent.Value; ! ! // BUG: MS BCL 1.0 can't import a key which ! // isn't the same size as the one present in ! // the container. ! int keySize = (rsaParams.Modulus.Length << 3); ! RSAManaged rsa = new RSAManaged(keySize); ! rsa.ImportParameters (rsaParams); ! ! return (RSA)rsa; ! } ! ! private byte[] getUnsignedBigInteger(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, 1, uinteger, 0, length); ! return uinteger; ! } ! else ! return integer; ! } ! ! #endregion ! } ! } --- 1,145 ---- ! /* Transport Security Layer (TLS) ! * Copyright (c) 2003 Carlos Guzmán Álvarez ! * ! * Permission is hereby granted, free of charge, to any person ! * obtaining a copy of this software and associated documentation ! * files (the "Software"), to deal in the Software without restriction, ! * including without limitation the rights to use, copy, modify, merge, ! * publish, distribute, sublicense, and/or sell copies of the Software, ! * and to permit persons to whom the Software is furnished to do so, ! * subject to the following conditions: ! * ! * The above copyright notice and this permission notice shall be included ! * in all copies or substantial portions of the Software. ! * ! * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ! * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES ! * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ! * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT ! * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, ! * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ! * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ! * DEALINGS IN THE SOFTWARE. ! */ ! ! using System; ! using System.Security.Cryptography.X509Certificates; ! ! using System.Security.Cryptography; ! using Mono.Security.Cryptography; ! ! namespace Mono.Security.Protocol.Tls.Handshake.Client ! { ! internal class TlsClientCertificateVerify : TlsHandshakeMessage ! { ! #region Constructors ! ! public TlsClientCertificateVerify(TlsContext context) ! : base(context, TlsHandshakeType.Finished) ! { ! } ! ! #endregion ! ! #region Methods ! ! public override void Update() ! { ! base.Update(); ! this.Reset(); ! } ! ! #endregion ! ! #region Protected Methods ! ! protected override void ProcessAsSsl3() ! { ! throw new NotSupportedException(); ! } ! ! protected override void ProcessAsTls1() ! { ! AsymmetricAlgorithm privKey = this.Context.SslStream.RaisePrivateKeySelection( ! this.Context.ClientSettings.ClientCertificate, ! this.Context.ClientSettings.TargetHost); ! ! // Compute handshake messages hash ! MD5SHA1 hash = new MD5SHA1(); ! hash.ComputeHash( ! this.Context.HandshakeMessages.ToArray(), ! 0, ! (int)this.Context.HandshakeMessages.Length); ! ! // RSAManaged of the selected ClientCertificate ! // (at this moment the first one) ! RSA rsa = getClientCertRSA((RSA)privKey); ! ! // Write message ! Write(hash.CreateSignature(rsa)); ! } ! ! #endregion ! ! #region Private methods ! ! private RSA getClientCertRSA(RSA privKey) ! { ! RSAParameters rsaParams = new RSAParameters(); ! RSAParameters privateParams = privKey.ExportParameters(true); ! ! // for RSA m_publickey contains 2 ASN.1 integers ! // the modulus and the public exponent ! ASN1 pubkey = new ASN1 (this.Context.ClientSettings.Certificates[0].GetPublicKey()); ! ASN1 modulus = pubkey [0]; ! if ((modulus == null) || (modulus.Tag != 0x02)) ! { ! return null; ! } ! ASN1 exponent = pubkey [1]; ! if (exponent.Tag != 0x02) ! { ! return null; ! } ! ! rsaParams.Modulus = this.getUnsignedBigInteger(modulus.Value); ! rsaParams.Exponent = exponent.Value; ! ! // Set private key parameters ! rsaParams.D = privateParams.D; ! rsaParams.DP = privateParams.DP; ! rsaParams.DQ = privateParams.DQ; ! rsaParams.InverseQ = privateParams.InverseQ; ! rsaParams.P = privateParams.P; ! rsaParams.Q = privateParams.Q; ! ! // BUG: MS BCL 1.0 can't import a key which ! // isn't the same size as the one present in ! // the container. ! int keySize = (rsaParams.Modulus.Length << 3); ! RSAManaged rsa = new RSAManaged(keySize); ! rsa.ImportParameters (rsaParams); ! ! return (RSA)rsa; ! } ! ! private byte[] getUnsignedBigInteger(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, 1, uinteger, 0, length); ! return uinteger; ! } ! else ! { ! return integer; ! } ! } ! ! #endregion ! } ! } |
|
From: <car...@us...> - 2004-02-08 22:28:30
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28927 Modified Files: SslClientStream.cs TlsClientSettings.cs Log Message: Updated files Index: SslClientStream.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/SslClientStream.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** SslClientStream.cs 23 Dec 2003 18:26:14 -0000 1.12 --- SslClientStream.cs 8 Feb 2004 22:25:24 -0000 1.13 *************** *** 1,1125 **** ! /* Transport Security Layer (TLS) ! * Copyright (c) 2003 Carlos Guzmán Álvarez ! * ! * Permission is hereby granted, free of charge, to any person ! * obtaining a copy of this software and associated documentation ! * files (the "Software"), to deal in the Software without restriction, ! * including without limitation the rights to use, copy, modify, merge, ! * publish, distribute, sublicense, and/or sell copies of the Software, ! * and to permit persons to whom the Software is furnished to do so, ! * subject to the following conditions: [...2264 lines suppressed...] ! return null; ! } ! ! internal AsymmetricAlgorithm RaisePrivateKeySelection( ! X509Certificate clientCertificate, ! string targetHost) ! { ! if (this.PrivateKeySelection != null) ! { ! return this.PrivateKeySelection( ! clientCertificate, ! targetHost); ! } ! ! return null; ! } ! ! #endregion ! } ! } Index: TlsClientSettings.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/TlsClientSettings.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TlsClientSettings.cs 14 Dec 2003 14:59:39 -0000 1.2 --- TlsClientSettings.cs 8 Feb 2004 22:25:24 -0000 1.3 *************** *** 1,81 **** ! /* Transport Security Layer (TLS) ! * Copyright (c) 2003 Carlos Guzmán Álvarez ! * ! * Permission is hereby granted, free of charge, to any person ! * obtaining a copy of this software and associated documentation ! * files (the "Software"), to deal in the Software without restriction, ! * including without limitation the rights to use, copy, modify, merge, ! * publish, distribute, sublicense, and/or sell copies of the Software, ! * and to permit persons to whom the Software is furnished to do so, ! * subject to the following conditions: ! * ! * The above copyright notice and this permission notice shall be included ! * in all copies or substantial portions of the Software. ! * ! * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ! * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES ! * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ! * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT ! * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, ! * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ! * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ! * DEALINGS IN THE SOFTWARE. ! */ ! ! using System; ! using System.Text; ! using System.Security.Cryptography.X509Certificates; ! ! namespace Mono.Security.Protocol.Tls ! { ! internal sealed class TlsClientSettings ! { ! #region Fields ! ! private string targetHost; ! private X509CertificateCollection certificates; ! private SecurityCompressionType compressionMethod; ! ! #endregion ! ! #region Properties ! ! public string TargetHost ! { ! get { return this.targetHost; } ! set { this.targetHost = value; } ! } ! ! public X509CertificateCollection Certificates ! { ! get { return this.certificates; } ! set { this.certificates = value; } ! } ! ! public SecurityCompressionType CompressionMethod ! { ! get { return this.compressionMethod; } ! set ! { ! if (value != SecurityCompressionType.None) ! { ! throw new NotSupportedException("Specified compression method is not supported"); ! } ! this.compressionMethod = value; ! } ! } ! ! #endregion ! ! #region Constructors ! ! public TlsClientSettings() ! { ! this.compressionMethod = SecurityCompressionType.None; ! this.certificates = new X509CertificateCollection(); ! this.targetHost = String.Empty; ! } ! ! #endregion ! } ! } --- 1,89 ---- ! /* Transport Security Layer (TLS) ! * Copyright (c) 2003 Carlos Guzmán Álvarez ! * ! * Permission is hereby granted, free of charge, to any person ! * obtaining a copy of this software and associated documentation ! * files (the "Software"), to deal in the Software without restriction, ! * including without limitation the rights to use, copy, modify, merge, ! * publish, distribute, sublicense, and/or sell copies of the Software, ! * and to permit persons to whom the Software is furnished to do so, ! * subject to the following conditions: ! * ! * The above copyright notice and this permission notice shall be included ! * in all copies or substantial portions of the Software. ! * ! * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ! * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES ! * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ! * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT ! * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, ! * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ! * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ! * DEALINGS IN THE SOFTWARE. ! */ ! ! using System; ! using System.Text; ! using System.Security.Cryptography.X509Certificates; ! ! namespace Mono.Security.Protocol.Tls ! { ! internal sealed class TlsClientSettings ! { ! #region Fields ! ! private string targetHost; ! private X509CertificateCollection certificates; ! private SecurityCompressionType compressionMethod; ! private X509Certificate clientCertificate; ! ! #endregion ! ! #region Properties ! ! public string TargetHost ! { ! get { return this.targetHost; } ! set { this.targetHost = value; } ! } ! ! public X509CertificateCollection Certificates ! { ! get { return this.certificates; } ! set { this.certificates = value; } ! } ! ! public SecurityCompressionType CompressionMethod ! { ! get { return this.compressionMethod; } ! set ! { ! if (value != SecurityCompressionType.None) ! { ! throw new NotSupportedException("Specified compression method is not supported"); ! } ! this.compressionMethod = value; ! } ! } ! ! public X509Certificate ClientCertificate ! { ! get { return this.clientCertificate; } ! set { this.clientCertificate = value; } ! } ! ! ! #endregion ! ! #region Constructors ! ! public TlsClientSettings() ! { ! this.compressionMethod = SecurityCompressionType.None; ! this.certificates = new X509CertificateCollection(); ! this.targetHost = String.Empty; ! } ! ! #endregion ! } ! } |
|
From: <car...@us...> - 2004-02-08 22:27:44
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28797 Modified Files: Build.bat makefile PgSqlClient.build Log Message: Updated build files Index: Build.bat =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Build.bat,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Build.bat 30 Sep 2003 19:54:35 -0000 1.1 --- Build.bat 8 Feb 2004 22:24:37 -0000 1.2 *************** *** 1 **** --- 1,2 ---- nant -buildfile:PgSqlClient.build -verbose %1 %2 %3 %4 + pause Index: makefile =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/makefile,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** makefile 26 Dec 2003 11:18:32 -0000 1.10 --- makefile 8 Feb 2004 22:24:37 -0000 1.11 *************** *** 1,48 **** ! TLS = Mono.Security.Tls.dll ! LIBRARY = PostgreSql.Data.PgSqlClient.dll ! NUNIT_SUITE = PostgreSql.Data.PgSqlClient.UnitTests.dll ! ! all: ${TLS} $(LIBRARY) $(NUNIT_SUITE) install clean ! ! CSC = mcs ! COPY = cp ! ! # References to assemblies ! LD_BASIC_FLAGS = -reference:System.dll -reference:System.Data.dll -reference:System.Drawing.dll -reference:System.Xml.dll ! LD_FLAGS = -reference:System.dll -reference:System.Design.dll -reference:System.Data.dll -reference:System.Drawing.dll -reference:System.Xml.dll ! ! # Resources for the Toolbox ! TOOL_RESOURCES = -resource:PostgreSql.Data.PgSqlClient/source/Resources/ToolBox/PgConnection.bmp,PostgreSql.Data.PgSqlClient.Resources.ToolBox.PgConnection.bmp -resource:PostgreSql.Data.PgSqlClient/source/Resources/ToolBox/PgCommand.bmp,PostgreSql.Data.PgSqlClient.Resources.ToolBox.PgCommand.bmp -resource:PostgreSql.Data.PgSqlClient/source/Resources/ToolBox/PgDataAdapter.bmp,PostgreSql.Data.PgSqlClient.Resources.ToolBox.PgDataAdapter.bmp ! ! # Source files ! RECURSE_TLS = -recurse:./Mono.Security.Protocol.Tls/*.cs ! RECURSE_SOURCE = -recurse:./PostgreSql.Data.PgSqlClient/source/*.cs ! RECURSE_TESTS = -recurse:./PostgreSql.Data.PgSqlClient.UnitTests/source/*.cs ! ! # COnfiguration files ! NUNIT_CONFIG=./PostgreSql.Data.PgSqlClient.UnitTests/PostgreSql.Data.PgSqlClient.UnitTests.dll.config ! ! # Defines ! DEFINE = -define:_DEBUG ! ! Mono.Security.Tls.dll: ! $(CSC) -target:library -out:$(TLS) $(LD_BASIC_FLAGS) $(DEFINE) $(RECURSE_TLS) ! ! PostgreSql.Data.PgSqlClient.dll: ! $(CSC) -target:library -out:$(LIBRARY) $(LD_FLAGS) -reference:Mono.Security.Tls.dll $(DEFINE) $(TOOL_RESOURCES) $(RECURSE_SOURCE) ! ! PostgreSql.Data.PgSqlClient.UnitTests.dll: ! $(CSC) -target:library -out:$(NUNIT_SUITE) $(LD_BASIC_FLAGS) -reference:${LIBRARY} -reference:NUnit.Framework.dll $(DEFINE) $(TOOL_RESOURCES) $(RECURSE_TESTS) ! ! install: ! rm -rf build ! mkdir -p build ! $(COPY) $(TLS) ./build ! $(COPY) $(LIBRARY) ./build ! $(COPY) $(NUNIT_SUITE) ./build ! $(COPY) ${NUNIT_CONFIG} ./build ! ! clean: ! rm $(TLS) rm $(LIBRARY) rm ${NUNIT_SUITE} \ No newline at end of file --- 1,48 ---- ! TLS = Mono.Security.Tls.dll ! LIBRARY = PostgreSql.Data.PgSqlClient.dll ! NUNIT_SUITE = PostgreSql.Data.PgSqlClient.UnitTests.dll ! ! all: ${TLS} $(LIBRARY) $(NUNIT_SUITE) install clean ! ! CSC = mcs ! COPY = cp ! ! # References to assemblies ! LD_BASIC_FLAGS = -reference:System.dll -reference:System.Data.dll -reference:System.Drawing.dll -reference:System.Xml.dll ! LD_FLAGS = -reference:System.dll -reference:System.Design.dll -reference:System.Data.dll -reference:System.Drawing.dll -reference:System.Xml.dll ! ! # Resources for the Toolbox ! TOOL_RESOURCES = -resource:PostgreSql.Data.PgSqlClient/source/Resources/ToolBox/PgConnection.bmp,PostgreSql.Data.PgSqlClient.Resources.ToolBox.PgConnection.bmp -resource:PostgreSql.Data.PgSqlClient/source/Resources/ToolBox/PgCommand.bmp,PostgreSql.Data.PgSqlClient.Resources.ToolBox.PgCommand.bmp -resource:PostgreSql.Data.PgSqlClient/source/Resources/ToolBox/PgDataAdapter.bmp,PostgreSql.Data.PgSqlClient.Resources.ToolBox.PgDataAdapter.bmp ! ! # Source files ! RECURSE_TLS = -recurse:./Mono.Security.Protocol.Tls/*.cs ! RECURSE_SOURCE = -recurse:./PostgreSql.Data.PgSqlClient/source/*.cs ! RECURSE_TESTS = -recurse:./PostgreSql.Data.PgSqlClient.UnitTests/source/*.cs ! ! # COnfiguration files ! NUNIT_CONFIG=./PostgreSql.Data.PgSqlClient.UnitTests/PostgreSql.Data.PgSqlClient.UnitTests.dll.config ! ! # Defines ! DEFINE = -define:_DEBUG ! ! Mono.Security.Tls.dll: ! $(CSC) -target:library -unsafe -out:$(TLS) $(LD_BASIC_FLAGS) $(DEFINE) $(RECURSE_TLS) ! ! PostgreSql.Data.PgSqlClient.dll: ! $(CSC) -target:library -out:$(LIBRARY) $(LD_FLAGS) -reference:Mono.Security.Tls.dll $(DEFINE) $(TOOL_RESOURCES) $(RECURSE_SOURCE) ! ! PostgreSql.Data.PgSqlClient.UnitTests.dll: ! $(CSC) -target:library -out:$(NUNIT_SUITE) $(LD_BASIC_FLAGS) -reference:${LIBRARY} -reference:NUnit.Framework.dll $(DEFINE) $(TOOL_RESOURCES) $(RECURSE_TESTS) ! ! install: ! rm -rf build ! mkdir -p build ! $(COPY) $(TLS) ./build ! $(COPY) $(LIBRARY) ./build ! $(COPY) $(NUNIT_SUITE) ./build ! $(COPY) ${NUNIT_CONFIG} ./build ! ! clean: ! rm $(TLS) rm $(LIBRARY) rm ${NUNIT_SUITE} \ No newline at end of file Index: PgSqlClient.build =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PgSqlClient.build,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** PgSqlClient.build 19 Nov 2003 23:08:19 -0000 1.10 --- PgSqlClient.build 8 Feb 2004 22:24:38 -0000 1.11 *************** *** 149,152 **** --- 149,153 ---- </references> <arg value="/optimize+" /> + <arg value="/unsafe" /> </csc> </target> |
|
From: <car...@us...> - 2004-01-03 15:44:47
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10 In directory sc8-pr-cvs1:/tmp/cvs-serv26434 Modified Files: changelog.txt Log Message: Updated changelog.txt Index: changelog.txt =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/changelog.txt,v retrieving revision 1.86 retrieving revision 1.87 diff -C2 -d -r1.86 -r1.87 *** changelog.txt 18 Dec 2003 10:12:57 -0000 1.86 --- changelog.txt 3 Jan 2004 15:44:44 -0000 1.87 *************** *** 3,6 **** --- 3,16 ---- + 2004-01-03 Carlos Guzmán Álvarez <car...@te...> + + * source/PgCommand.cs: + * source/NPgClient/PgStatement.cs: + * source/NPgClient/PgResponsePacket.cs: + + - Added an initial implementation of the simple query protocol + that will be available using an SIMPLE_PROTOCOL define at build time. + + < --------------------------- Beta 6 ------------------------------ > |
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgTypes
In directory sc8-pr-cvs1:/tmp/cvs-serv26336
Modified Files:
PgBox.cs PgCircle.cs PgLine.cs PgLSeg.cs PgPath.cs PgPoint.cs
PgPolygon.cs
Log Message:
Added new Parse method
Index: PgBox.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgTypes/PgBox.cs,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** PgBox.cs 18 Dec 2003 11:47:05 -0000 1.8
--- PgBox.cs 3 Jan 2004 15:44:10 -0000 1.9
***************
*** 121,124 ****
--- 121,133 ----
#endregion
+
+ #region Static Methods
+
+ public static PgBox Parse(string s)
+ {
+ throw new NotSupportedException();
+ }
+
+ #endregion
}
}
Index: PgCircle.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgTypes/PgCircle.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** PgCircle.cs 18 Dec 2003 11:47:05 -0000 1.6
--- PgCircle.cs 3 Jan 2004 15:44:10 -0000 1.7
***************
*** 118,121 ****
--- 118,130 ----
#endregion
+
+ #region Static Methods
+
+ public static PgCircle Parse(string s)
+ {
+ throw new NotSupportedException();
+ }
+
+ #endregion
}
}
Index: PgLine.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgTypes/PgLine.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** PgLine.cs 18 Dec 2003 11:47:05 -0000 1.6
--- PgLine.cs 3 Jan 2004 15:44:10 -0000 1.7
***************
*** 121,124 ****
--- 121,133 ----
#endregion
+
+ #region Static Methods
+
+ public static PgLine Parse(string s)
+ {
+ throw new NotSupportedException();
+ }
+
+ #endregion
}
}
Index: PgLSeg.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgTypes/PgLSeg.cs,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** PgLSeg.cs 18 Dec 2003 11:47:05 -0000 1.7
--- PgLSeg.cs 3 Jan 2004 15:44:10 -0000 1.8
***************
*** 121,124 ****
--- 121,133 ----
#endregion
+
+ #region Static Methods
+
+ public static PgLSeg Parse(string s)
+ {
+ throw new NotSupportedException();
+ }
+
+ #endregion
}
}
Index: PgPath.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgTypes/PgPath.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** PgPath.cs 18 Dec 2003 11:47:05 -0000 1.6
--- PgPath.cs 3 Jan 2004 15:44:10 -0000 1.7
***************
*** 139,142 ****
--- 139,151 ----
#endregion
+
+ #region Static Methods
+
+ public static PgPath Parse(string s)
+ {
+ throw new NotSupportedException();
+ }
+
+ #endregion
}
}
Index: PgPoint.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgTypes/PgPoint.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** PgPoint.cs 18 Dec 2003 11:47:05 -0000 1.6
--- PgPoint.cs 3 Jan 2004 15:44:10 -0000 1.7
***************
*** 111,114 ****
--- 111,123 ----
#endregion
+
+ #region Static Methods
+
+ public static PgPoint Parse(string s)
+ {
+ throw new NotSupportedException();
+ }
+
+ #endregion
}
}
Index: PgPolygon.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgTypes/PgPolygon.cs,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** PgPolygon.cs 18 Dec 2003 11:47:05 -0000 1.7
--- PgPolygon.cs 3 Jan 2004 15:44:10 -0000 1.8
***************
*** 132,135 ****
--- 132,144 ----
#endregion
+
+ #region Static Methods
+
+ public static PgPolygon Parse(string s)
+ {
+ throw new NotSupportedException();
+ }
+
+ #endregion
}
}
|
|
From: <car...@us...> - 2004-01-03 15:43:48
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient
In directory sc8-pr-cvs1:/tmp/cvs-serv26231
Modified Files:
PgResponsePacket.cs
Log Message:
2004-01-03 Carlos Guzmán Álvarez <car...@te...>
* source/PgCommand.cs:
* source/NPgClient/PgStatement.cs:
* source/NPgClient/PgResponsePacket.cs:
- Added an initial implementation of the simple query protocol
that will be available using an SIMPLE_PROTOCOL define at build time.
Index: PgResponsePacket.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient/PgResponsePacket.cs,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** PgResponsePacket.cs 18 Dec 2003 10:27:32 -0000 1.22
--- PgResponsePacket.cs 3 Jan 2004 15:43:45 -0000 1.23
***************
*** 441,446 ****
case PgDataType.Decimal:
! string numericValue = this.ReadString(length);
! return Decimal.Parse(numericValue, NumberFormatInfo.InvariantInfo);
case PgDataType.Currency:
--- 441,447 ----
case PgDataType.Decimal:
! return Decimal.Parse(
! this.ReadString(length),
! NumberFormatInfo.InvariantInfo);
case PgDataType.Currency:
***************
*** 500,503 ****
--- 501,607 ----
case PgDataType.Path:
return this.ReadPath();
+
+ default:
+ return ReadBytes(length);
+ }
+ }
+
+ public object ReadValueFromString(PgType type, int length)
+ {
+ string stringValue = this.ReadString(length);
+
+ switch (type.DataType)
+ {
+ case PgDataType.Array:
+ return null;
+
+ case PgDataType.Vector:
+ return null;
+
+ case PgDataType.Binary:
+ return null;
+
+ case PgDataType.Char:
+ case PgDataType.VarChar:
+ return stringValue;
+
+ case PgDataType.Boolean:
+ switch (stringValue.ToLower())
+ {
+ case "t":
+ case "true":
+ case "y":
+ case "yes":
+ case "1":
+ return true;
+
+ default:
+ return false;
+ }
+
+ case PgDataType.Byte:
+ return Byte.Parse(stringValue);
+
+ case PgDataType.Decimal:
+ return Decimal.Parse(
+ stringValue,
+ NumberFormatInfo.InvariantInfo);
+
+ case PgDataType.Currency:
+ case PgDataType.Float:
+ return Single.Parse(
+ stringValue,
+ NumberFormatInfo.InvariantInfo);
+
+ case PgDataType.Double:
+ return Double.Parse(
+ stringValue,
+ NumberFormatInfo.InvariantInfo);
+
+ case PgDataType.Int2:
+ return Int16.Parse(
+ stringValue,
+ NumberFormatInfo.InvariantInfo);
+
+ case PgDataType.Int4:
+ return Int32.Parse(
+ stringValue,
+ NumberFormatInfo.InvariantInfo);
+
+ case PgDataType.Int8:
+ return Int64.Parse(
+ stringValue,
+ NumberFormatInfo.InvariantInfo);
+
+ case PgDataType.Interval:
+ return null;
+
+ case PgDataType.Date:
+ case PgDataType.Timestamp:
+ case PgDataType.Time:
+ case PgDataType.TimeWithTZ:
+ case PgDataType.TimestampWithTZ:
+ return DateTime.Parse(stringValue);
+
+ case PgDataType.Point:
+ return PgPoint.Parse(stringValue);
+
+ case PgDataType.Circle:
+ return PgCircle.Parse(stringValue);
+
+ case PgDataType.Line:
+ return PgLine.Parse(stringValue);
+
+ case PgDataType.LSeg:
+ return PgLSeg.Parse(stringValue);
+
+ case PgDataType.Box:
+ return PgBox.Parse(stringValue);
+
+ case PgDataType.Polygon:
+ return PgPolygon.Parse(stringValue);
+
+ case PgDataType.Path:
+ return PgPath.Parse(stringValue);
default:
|
|
From: <car...@us...> - 2004-01-03 15:43:13
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient
In directory sc8-pr-cvs1:/tmp/cvs-serv26115
Modified Files:
PgStatement.cs
Log Message:
Updated file
Index: PgStatement.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient/PgStatement.cs,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** PgStatement.cs 18 Dec 2003 10:27:32 -0000 1.20
--- PgStatement.cs 3 Jan 2004 15:43:07 -0000 1.21
***************
*** 33,36 ****
--- 33,37 ----
Binded,
Executed,
+ OnQuery,
Error
}
***************
*** 430,433 ****
--- 431,436 ----
public void Query()
{
+ ArrayList innerRows = new ArrayList();
+
lock (db)
{
***************
*** 441,444 ****
--- 444,453 ----
db.SendData(packet.GetPacketBytes(PgFrontEndCodes.QUERY));
+ // Update Status
+ this.status = PgStatementStatus.OnQuery;
+
+ // Set fetch size
+ this.fetchSize = 1;
+
// Receive response
PgResponsePacket response = new PgResponsePacket();
***************
*** 447,451 ****
--- 456,482 ----
response = db.ReceiveResponsePacket();
processSqlPacket(response);
+
+ if (this.hasRows &&
+ response.Message == PgBackendCodes.DATAROW)
+ {
+ innerRows.Add(this.rows[0]);
+ this.rowIndex = 0;
+ }
}
+
+ if (this.hasRows)
+ {
+ // Obtain all the rows
+ this.rows = (object[])innerRows.ToArray(typeof(object));
+
+ // reset rowIndex
+ this.rowIndex = 0;
+
+ // Set allRowsFetched flag
+ this.allRowsFetched = true;
+ }
+
+ // reset fetch size
+ this.fetchSize = 200;
// Update status
***************
*** 487,490 ****
--- 518,522 ----
if (this.rows != null &&
(this.rowIndex >= this.fetchSize ||
+ this.rowIndex >= this.rows.Length ||
this.rows[this.rowIndex] == null))
{
***************
*** 720,726 ****
default:
! values[i] = packet.ReadValue(
! rowDescriptor.Fields[i].DataType,
! length);
break;
}
--- 752,767 ----
default:
! if (this.status == PgStatementStatus.OnQuery)
! {
! values[i] = packet.ReadValueFromString(
! rowDescriptor.Fields[i].DataType,
! length);
! }
! else
! {
! values[i] = packet.ReadValue(
! rowDescriptor.Fields[i].DataType,
! length);
! }
break;
}
|
|
From: <car...@us...> - 2004-01-03 15:42:19
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source
In directory sc8-pr-cvs1:/tmp/cvs-serv25914
Modified Files:
PgParameter.cs
Log Message:
Updated file
Index: PgParameter.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgParameter.cs,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** PgParameter.cs 14 Dec 2003 15:06:50 -0000 1.9
--- PgParameter.cs 3 Jan 2004 15:42:16 -0000 1.10
***************
*** 21,24 ****
--- 21,26 ----
using System.ComponentModel;
+ using PostgreSql.Data.PgTypes;
+
namespace PostgreSql.Data.PgSqlClient
{
***************
*** 220,224 ****
#endregion
! #region ICLONEABLE_METHOD
object ICloneable.Clone()
--- 222,226 ----
#endregion
! #region ICloneable Method
object ICloneable.Clone()
***************
*** 238,241 ****
--- 240,379 ----
#endregion
+ #region Methods
+
+ public override string ToString()
+ {
+ return this.parameterName;
+ }
+
+ #endregion
+
+ #region Internal Methods
+
+ internal string ConvertToPgString()
+ {
+ bool addQuotes = true;
+ string returnValue = String.Empty;
+
+ switch (this.pgDbType)
+ {
+ case PgDbType.Array:
+ break;
+
+ case PgDbType.Binary:
+ break;
+
+ case PgDbType.Boolean:
+ returnValue = Convert.ToBoolean(this.value).ToString().ToLower();
+ break;
+
+ case PgDbType.Box:
+ returnValue = ((PgBox)this.value).ToString();
+ break;
+
+ case PgDbType.Byte:
+ returnValue = Convert.ToByte(this.value).ToString();
+ break;
+
+ case PgDbType.Char:
+ case PgDbType.VarChar:
+ case PgDbType.Text:
+ returnValue = Convert.ToString(this.value);
+ break;
+
+ case PgDbType.Circle:
+ returnValue = ((PgCircle)this.value).ToString();
+ break;
+
+ case PgDbType.Currency:
+ returnValue = "$" + Convert.ToSingle(this.value).ToString();
+ break;
+
+ case PgDbType.Date:
+ returnValue = Convert.ToDateTime(this.value).ToString("MM/dd/yyyy");
+ break;
+
+ case PgDbType.Decimal:
+ case PgDbType.Numeric:
+ returnValue = Convert.ToDecimal(this.value).ToString();
+ break;
+
+ case PgDbType.Double:
+ returnValue = Convert.ToDouble(this.value).ToString();
+ break;
+
+ case PgDbType.Float:
+ returnValue = Convert.ToSingle(this.value).ToString();
+ break;
+
+ case PgDbType.Int2:
+ returnValue = Convert.ToInt16(this.value).ToString();
+ break;
+
+ case PgDbType.Int4:
+ returnValue = Convert.ToInt32(this.value).ToString();
+ break;
+
+ case PgDbType.Int8:
+ returnValue = Convert.ToInt64(this.value).ToString();
+ break;
+
+ case PgDbType.Interval:
+ break;
+
+ case PgDbType.Line:
+ returnValue = ((PgLine)this.value).ToString();
+ break;
+
+ case PgDbType.LSeg:
+ returnValue = ((PgLSeg)this.value).ToString();
+ break;
+
+ case PgDbType.Path:
+ returnValue = ((PgPath)this.value).ToString();
+ break;
+
+ case PgDbType.Point:
+ returnValue = ((PgPoint)this.value).ToString();
+ break;
+
+ case PgDbType.Polygon:
+ returnValue = ((PgPolygon)this.value).ToString();
+ break;
+
+ case PgDbType.Time:
+ returnValue = Convert.ToDateTime(this.value).ToString("HH:mm:ss");
+ break;
+
+ case PgDbType.Timestamp:
+ returnValue = Convert.ToDateTime(this.value).ToString("MM/dd/yyy HH:mm:ss");
+ break;
+
+ case PgDbType.TimestampWithTZ:
+ returnValue = Convert.ToDateTime(this.value).ToString("MM/dd/yyy HH:mm:ss zz");
+ break;
+
+ case PgDbType.TimeWithTZ:
+ returnValue = Convert.ToDateTime(this.value).ToString("HH:mm:ss zz");
+ break;
+
+ case PgDbType.Vector:
+ break;
+
+ default:
+ returnValue = this.value.ToString();
+ break;
+ }
+
+ if (addQuotes)
+ {
+ returnValue = "'" + returnValue + "'";
+ }
+
+ return returnValue;
+ }
+
+ #endregion
+
#region Private Methods
***************
*** 421,429 ****
}
- public override string ToString()
- {
- return this.parameterName;
- }
-
#endregion
}
--- 559,562 ----
|
|
From: <car...@us...> - 2004-01-03 15:41:41
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source
In directory sc8-pr-cvs1:/tmp/cvs-serv25678
Modified Files:
PgCommand.cs
Log Message:
2004-01-03 Carlos Guzmán Álvarez <car...@te...>
* source/PgCommand.cs:
- Added an initial implementation of the simple query protocol
that will be available using an SIMPLE_PROTOCOL define at build time.
Index: PgCommand.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgCommand.cs,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** PgCommand.cs 18 Dec 2003 10:27:32 -0000 1.24
--- PgCommand.cs 3 Jan 2004 15:41:38 -0000 1.25
***************
*** 51,54 ****
--- 51,55 ----
private int matchIndex;
private Hashtable matchReplaces;
+ private bool isPrepared;
private PgStatement statement;
***************
*** 74,78 ****
this.commandText = value;
this.actualCommand = 0;
! this.commands = null;
}
}
--- 75,79 ----
this.commandText = value;
this.actualCommand = 0;
! this.commands = null;
}
}
***************
*** 297,301 ****
public void Cancel()
! {
throw new NotSupportedException();
}
--- 298,302 ----
public void Cancel()
! {
throw new NotSupportedException();
}
***************
*** 316,323 ****
this.splitBatchCommands(false);
this.InternalPrepare();
this.InternalExecute();
! InternalSetOutputParameters();
return this.statement.RecordsAffected;
--- 317,336 ----
this.splitBatchCommands(false);
+
+ #if (SIMPLE_PROTOCOL)
+ if (this.isPrepared)
+ {
+ this.InternalExecute();
+ }
+ else
+ {
+ this.InternalQuery();
+ }
+ #else
this.InternalPrepare();
this.InternalExecute();
+ #endif
! this.InternalSetOutputParameters();
return this.statement.RecordsAffected;
***************
*** 343,350 ****
this.checkCommand();
! commandBehavior = behavior;
this.splitBatchCommands(true);
this.InternalPrepare();
if ((commandBehavior & System.Data.CommandBehavior.SequentialAccess) == System.Data.CommandBehavior.SequentialAccess ||
--- 356,366 ----
this.checkCommand();
! this.commandBehavior = behavior;
this.splitBatchCommands(true);
+
+ #if (!SIMPLE_PROTOCOL)
this.InternalPrepare();
+ #endif
if ((commandBehavior & System.Data.CommandBehavior.SequentialAccess) == System.Data.CommandBehavior.SequentialAccess ||
***************
*** 354,358 ****
--- 370,385 ----
commandBehavior == System.Data.CommandBehavior.Default)
{
+ #if (SIMPLE_PROTOCOL)
+ if (this.isPrepared)
+ {
+ this.InternalExecute();
+ }
+ else
+ {
+ this.InternalQuery();
+ }
+ #else
this.InternalExecute();
+ #endif
}
***************
*** 367,372 ****
this.splitBatchCommands(false);
! this.InternalPrepare();
this.InternalExecute();
if (this.statement.HasRows)
--- 394,411 ----
this.splitBatchCommands(false);
!
! #if (SIMPLE_PROTOCOL)
! if (this.isPrepared)
! {
! this.InternalExecute();
! }
! else
! {
! this.InternalQuery();
! }
! #else
! this.InternalPrepare();
this.InternalExecute();
+ #endif
if (this.statement.HasRows)
***************
*** 383,388 ****
this.splitBatchCommands(false);
this.InternalPrepare();
- this.connection.ActiveCommands.Add(this);
}
--- 422,427 ----
this.splitBatchCommands(false);
+
this.InternalPrepare();
}
***************
*** 420,426 ****
internal void InternalPrepare()
{
! if (commands == null)
{
! splitBatchCommands(false);
}
--- 459,465 ----
internal void InternalPrepare()
{
! if (this.commands == null)
{
! this.splitBatchCommands(false);
}
***************
*** 431,441 ****
this.statement.Status == PgStatementStatus.Error)
{
! if (commandType == CommandType.StoredProcedure)
{
! commands[actualCommand] = parseSPCommandText();
}
// Get named parameters in CommandText
! namedParameters = search.Matches(commands[actualCommand]);
string prepareName = "PS" + getStmtName();
--- 470,481 ----
this.statement.Status == PgStatementStatus.Error)
{
! if (this.commandType == CommandType.StoredProcedure)
{
! this.commands[actualCommand] = this.parseSPCommandText();
}
// Get named parameters in CommandText
! this.namedParameters = this.search.Matches(
! this.commands[actualCommand]);
string prepareName = "PS" + getStmtName();
***************
*** 445,449 ****
prepareName,
portalName,
! parseParameterNames());
// Parse statement
--- 485,489 ----
prepareName,
portalName,
! this.parseParameterNames());
// Parse statement
***************
*** 452,455 ****
--- 492,504 ----
// Describe statement
this.statement.Describe();
+
+ // Add this command to the active command list
+ if (this.connection.ActiveCommands != null)
+ {
+ if (!this.connection.ActiveCommands.Contains(this))
+ {
+ this.connection.ActiveCommands.Add(this);
+ }
+ }
}
else
***************
*** 463,466 ****
--- 512,517 ----
throw new PgException(ex.Message, ex);
}
+
+ this.isPrepared = true;
}
***************
*** 469,476 ****
try
{
! if (parameters.Count != 0)
{
// Set parameter values
! setParameterValues();
}
--- 520,527 ----
try
{
! if (this.parameters.Count != 0)
{
// Set parameter values
! this.setParameterValues();
}
***************
*** 489,495 ****
internal void InternalQuery()
{
try
{
! this.statement = this.connection.DbConnection.DB.CreateStatement(commandText);
this.statement.Query();
}
--- 540,577 ----
internal void InternalQuery()
{
+ if (this.commands == null)
+ {
+ this.splitBatchCommands(false);
+ }
+
+ // Add this command to the active command list
+ if (this.connection.ActiveCommands != null)
+ {
+ if (!this.connection.ActiveCommands.Contains(this))
+ {
+ this.connection.ActiveCommands.Add(this);
+ }
+ }
+
try
{
! string commandText = String.Empty;
!
! commandText = null;
!
! if (this.commandType == CommandType.StoredProcedure)
! {
! this.commands[actualCommand] = this.parseSPCommandText();
! }
!
! // Get named parameters in CommandText
! this.namedParameters = this.search.Matches(
! this.commands[this.actualCommand]);
!
! this.statement = this.connection.DbConnection.DB.CreateStatement(
! String.Empty,
! String.Empty,
! this.parseParameterNames());
!
this.statement.Query();
}
***************
*** 498,501 ****
--- 580,587 ----
throw new PgException(ex.Message, ex);
}
+ finally
+ {
+ this.isPrepared = false;
+ }
}
***************
*** 515,518 ****
--- 601,606 ----
}
}
+
+ this.isPrepared = false;
}
***************
*** 521,525 ****
bool returnValue = false;
! if (commandBehavior != CommandBehavior.SingleResult)
{
this.actualCommand++;
--- 609,613 ----
bool returnValue = false;
! if ((this.CommandBehavior & CommandBehavior.SingleResult) != CommandBehavior.SingleResult)
{
this.actualCommand++;
***************
*** 539,545 ****
this.statement = null;
this.InternalPrepare();
this.InternalExecute();
!
returnValue = true;
}
--- 627,636 ----
this.statement = null;
+ #if (SIMPLE_PROTOCOL)
+ this.InternalQuery();
+ #else
this.InternalPrepare();
this.InternalExecute();
! #endif
returnValue = true;
}
***************
*** 647,652 ****
private string getStmtName()
{
! return GetHashCode().ToString() +
! this.connection.GetHashCode().ToString() +
DateTime.Now.Ticks;
}
--- 738,743 ----
private string getStmtName()
{
! return GetHashCode().ToString() +
! this.connection.GetHashCode().ToString() +
DateTime.Now.Ticks;
}
***************
*** 673,682 ****
private string matchEvaluator(Match match)
{
! if (!matchReplaces.ContainsKey(match.Value))
{
! matchReplaces.Add(match.Value, "$" + ((matchIndex++) + 1).ToString());
}
!
! return matchReplaces[match.Value].ToString();
}
--- 764,783 ----
private string matchEvaluator(Match match)
{
! if (!this.matchReplaces.ContainsKey(match.Value))
{
! if (this.isPrepared)
! {
! this.matchReplaces.Add(
! match.Value,
! "$" + ((matchIndex++) + 1).ToString());
! }
! else
! {
! this.matchReplaces.Add(
! match.Value,
! this.parameters[matchIndex++].ConvertToPgString());
! }
}
! return this.matchReplaces[match.Value].ToString();
}
***************
*** 687,707 ****
for (int i = 0; i < this.statement.Parameters.Length; i++)
{
! string parameterName = parameters[i].ParameterName;
if (namedParameters.Count != 0)
{
try
{
! parameterName = namedParameters[i].Value.Trim();
}
catch
{
! parameterName = parameters[i].ParameterName;
}
}
! int index = parameters.IndexOf(parameterName);
! if (parameters[index].Direction == ParameterDirection.Input ||
! parameters[index].Direction == ParameterDirection.InputOutput)
{
if (parameters[index].Value == System.DBNull.Value)
--- 788,808 ----
for (int i = 0; i < this.statement.Parameters.Length; i++)
{
! string parameterName = this.parameters[i].ParameterName;
if (namedParameters.Count != 0)
{
try
{
! parameterName = this.namedParameters[i].Value.Trim();
}
catch
{
! parameterName = this.parameters[i].ParameterName;
}
}
! int index = this.parameters.IndexOf(parameterName);
! if (this.parameters[index].Direction == ParameterDirection.Input ||
! this.parameters[index].Direction == ParameterDirection.InputOutput)
{
if (parameters[index].Value == System.DBNull.Value)
***************
*** 711,715 ****
else
{
! this.statement.Parameters[i].Value = parameters[index].Value;
}
}
--- 812,816 ----
else
{
! this.statement.Parameters[i].Value = this.parameters[index].Value;
}
}
|
|
From: <car...@us...> - 2003-12-26 11:18:35
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10 In directory sc8-pr-cvs1:/tmp/cvs-serv32681 Modified Files: makefile Log Message: Fixed typo Index: makefile =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/makefile,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** makefile 22 Dec 2003 09:32:10 -0000 1.9 --- makefile 26 Dec 2003 11:18:32 -0000 1.10 *************** *** 16,20 **** # Source files ! RECURSE_TLS = -recurse:./Mono.Security.Protocol.Tls//*.cs RECURSE_SOURCE = -recurse:./PostgreSql.Data.PgSqlClient/source/*.cs RECURSE_TESTS = -recurse:./PostgreSql.Data.PgSqlClient.UnitTests/source/*.cs --- 16,20 ---- # Source files ! RECURSE_TLS = -recurse:./Mono.Security.Protocol.Tls/*.cs RECURSE_SOURCE = -recurse:./PostgreSql.Data.PgSqlClient/source/*.cs RECURSE_TESTS = -recurse:./PostgreSql.Data.PgSqlClient.UnitTests/source/*.cs |
|
From: <car...@us...> - 2003-12-26 11:17:17
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls.Handshake/Mono.Security.Protocol.Tls.Handshake.Client
In directory sc8-pr-cvs1:/tmp/cvs-serv32542
Modified Files:
TlsClientCertificateVerify.cs TlsServerCertificate.cs
TlsServerKeyExchange.cs
Log Message:
Cleanup
Index: TlsClientCertificateVerify.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls.Handshake/Mono.Security.Protocol.Tls.Handshake.Client/TlsClientCertificateVerify.cs,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** TlsClientCertificateVerify.cs 14 Dec 2003 15:01:54 -0000 1.16
--- TlsClientCertificateVerify.cs 26 Dec 2003 11:17:14 -0000 1.17
***************
*** 68,73 ****
(int)this.Context.HandshakeMessages.Length);
// Write message
! Write(hash.CreateSignature(this.Context.Cipher.CertificateRSA()));
}
--- 68,122 ----
(int)this.Context.HandshakeMessages.Length);
+ // RSAManaged of the selected ClientCertificate
+ // (at this moment the first one)
+ RSA rsa = getClientCertRSA();
+
// Write message
! Write(hash.CreateSignature(rsa));
! }
!
! #endregion
!
! #region Private methods
!
! private RSA getClientCertRSA()
! {
! RSAParameters rsaParams = new RSAParameters();
! // for RSA m_publickey contains 2 ASN.1 integers
! // the modulus and the public exponent
! ASN1 pubkey = new ASN1 (this.Context.ClientSettings.Certificates[0].GetPublicKey());
! ASN1 modulus = pubkey [0];
! if ((modulus == null) || (modulus.Tag != 0x02))
! return null;
! ASN1 exponent = pubkey [1];
! if (exponent.Tag != 0x02)
! return null;
!
! rsaParams.Modulus = this.getUnsignedBigInteger(modulus.Value);
! rsaParams.Exponent = exponent.Value;
!
! // BUG: MS BCL 1.0 can't import a key which
! // isn't the same size as the one present in
! // the container.
! int keySize = (rsaParams.Modulus.Length << 3);
! RSAManaged rsa = new RSAManaged(keySize);
! rsa.ImportParameters (rsaParams);
!
! return (RSA)rsa;
! }
!
! private byte[] getUnsignedBigInteger(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, 1, uinteger, 0, length);
! return uinteger;
! }
! else
! return integer;
}
Index: TlsServerCertificate.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls.Handshake/Mono.Security.Protocol.Tls.Handshake.Client/TlsServerCertificate.cs,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** TlsServerCertificate.cs 14 Dec 2003 15:01:54 -0000 1.15
--- TlsServerCertificate.cs 26 Dec 2003 11:17:14 -0000 1.16
***************
*** 143,147 ****
if (!certificate.IsCurrent)
{
! errors.Add(0x800B0101);
}
--- 143,148 ----
if (!certificate.IsCurrent)
{
! // errors.Add(0x800B0101);
! errors.Add(0x01);
}
***************
*** 160,174 ****
if (!this.checkDomainName(certificate.SubjectName))
{
! errors.Add(0x800B010F);
}
if (errors.Count > 0)
{
! int[] certificateErrors = new int[errors.Count];
!
! for (int i = 0; i < certificateErrors.Length; i++)
! {
! certificateErrors[i] = Convert.ToInt32(errors[i]);
! }
if (!this.Context.SslStream.RaiseServerCertificateValidation(
--- 161,171 ----
if (!this.checkDomainName(certificate.SubjectName))
{
! // errors.Add(0x800B010F);
! errors.Add(0x02);
}
if (errors.Count > 0)
{
! int[] certificateErrors = (int[])errors.ToArray(typeof(int));
if (!this.Context.SslStream.RaiseServerCertificateValidation(
Index: TlsServerKeyExchange.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls.Handshake/Mono.Security.Protocol.Tls.Handshake.Client/TlsServerKeyExchange.cs,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** TlsServerKeyExchange.cs 21 Dec 2003 14:56:06 -0000 1.16
--- TlsServerKeyExchange.cs 26 Dec 2003 11:17:14 -0000 1.17
***************
*** 37,41 ****
private RSAParameters rsaParams;
private byte[] signedParams;
- private byte[] content;
#endregion
--- 37,40 ----
|
|
From: <car...@us...> - 2003-12-26 11:16:11
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Security/Mono.Security.X509 In directory sc8-pr-cvs1:/tmp/cvs-serv32346 Modified Files: X509Certificate.cs Log Message: Minor change Index: X509Certificate.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Security/Mono.Security.X509/X509Certificate.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** X509Certificate.cs 28 Oct 2003 16:12:06 -0000 1.1 --- X509Certificate.cs 26 Dec 2003 11:15:54 -0000 1.2 *************** *** 1,429 **** ! // ! // X509Certificates.cs: Handles X.509 certificates. ! // ! // Author: ! // Sebastien Pouliot (spo...@mo...) ! // ! // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) ! // ! ! using System; ! using System.Security.Cryptography; ! using SSCX = System.Security.Cryptography.X509Certificates; ! using System.Text; ! ! namespace Mono.Security.X509 { ! ! // References: ! // a. Internet X.509 Public Key Infrastructure Certificate and CRL Profile ! // http://www.ietf.org/rfc/rfc3280.txt ! // b. ITU ASN.1 standards (free download) ! // http://www.itu.int/ITU-T/studygroups/com17/languages/ ! ! internal class X509Certificate { ! ! private ASN1 decoder; ! ! private byte[] m_encodedcert; ! private DateTime m_from; ! private DateTime m_until; ! private string m_issuername; ! private string m_keyalgo; ! private byte[] m_keyalgoparams; ! private string m_subject; ! private byte[] m_publickey; ! private byte[] signature; ! private string m_signaturealgo; ! private byte[] m_signaturealgoparams; ! ! // from http://www.ietf.org/rfc/rfc2459.txt ! // ! //Certificate ::= SEQUENCE { ! // tbsCertificate TBSCertificate, ! // signatureAlgorithm AlgorithmIdentifier, ! // signature BIT STRING } ! // ! //TBSCertificate ::= SEQUENCE { ! // version [0] Version DEFAULT v1, ! // serialNumber CertificateSerialNumber, ! // signature AlgorithmIdentifier, ! // issuer Name, ! // validity Validity, ! // subject Name, ! // subjectPublicKeyInfo SubjectPublicKeyInfo, ! // issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL, ! // -- If present, version shall be v2 or v3 ! // subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL, ! // -- If present, version shall be v2 or v3 ! // extensions [3] Extensions OPTIONAL ! // -- If present, version shall be v3 -- } ! private int version; ! private byte[] serialnumber; ! ! private byte[] issuerUniqueID; ! private byte[] subjectUniqueID; ! private X509Extensions extensions; ! ! // that's were the real job is! ! private void Parse (byte[] data) ! { ! string e = "Input data cannot be coded as a valid certificate."; ! try { ! decoder = new ASN1 (data); ! // Certificate ! if (decoder.Tag != 0x30) ! throw new CryptographicException (e); ! // Certificate / TBSCertificate ! if (decoder [0].Tag != 0x30) ! throw new CryptographicException (e); ! ! ASN1 tbsCertificate = decoder [0]; ! ! int tbs = 0; ! // Certificate / TBSCertificate / Version ! ASN1 v = decoder [0][tbs]; ! version = 1; // DEFAULT v1 ! if (v.Tag == 0xA0) { ! // version (optional) is present only in v2+ certs ! version += v.Value [0]; // zero based ! tbs++; ! } ! ! // Certificate / TBSCertificate / CertificateSerialNumber ! ASN1 sn = decoder [0][tbs++]; ! if (sn.Tag != 0x02) ! throw new CryptographicException (e); ! serialnumber = sn.Value; ! Array.Reverse (serialnumber, 0, serialnumber.Length); ! ! // Certificate / TBSCertificate / AlgorithmIdentifier ! ASN1 signatureAlgo = tbsCertificate.Element (tbs++, 0x30); ! ! ASN1 issuer = tbsCertificate.Element (tbs++, 0x30); ! m_issuername = X501.ToString (issuer); ! ! ASN1 validity = tbsCertificate.Element (tbs++, 0x30); ! ASN1 notBefore = validity [0]; ! m_from = ASN1Convert.ToDateTime (notBefore); ! ASN1 notAfter = validity [1]; ! m_until = ASN1Convert.ToDateTime (notAfter); ! ! ASN1 subject = tbsCertificate.Element (tbs++, 0x30); ! m_subject = X501.ToString (subject); ! ! ASN1 subjectPublicKeyInfo = tbsCertificate.Element (tbs++, 0x30); ! ! 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 ! ASN1 parameters = algorithm [1]; ! m_keyalgoparams = parameters.GetBytes (); ! ! ASN1 subjectPublicKey = subjectPublicKeyInfo.Element (1, 0x03); ! // we must drop th first byte (which is the number of unused bits ! // in the BITSTRING) ! int n = subjectPublicKey.Length - 1; ! m_publickey = new byte [n]; ! Array.Copy (subjectPublicKey.Value, 1, m_publickey, 0, n); ! ! // signature processing ! byte[] bitstring = decoder [2].Value; ! // 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) ! m_signaturealgoparams = parameters.GetBytes (); ! else ! m_signaturealgoparams = null; ! ! // Certificate / TBSCertificate / issuerUniqueID ! ASN1 issuerUID = tbsCertificate.Element (tbs, 0xA1); ! if (issuerUID != null) { ! tbs++; ! issuerUniqueID = issuerUID.Value; ! } ! ! // Certificate / TBSCertificate / subjectUniqueID ! ASN1 subjectUID = tbsCertificate.Element (tbs, 0xA2); ! if (subjectUID != null) { ! tbs++; ! subjectUniqueID = subjectUID.Value; ! } ! ! // Certificate / TBSCertificate / Extensions ! 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 ! m_encodedcert = (byte[]) data.Clone (); ! } ! catch { ! throw new CryptographicException (e); ! } ! } ! ! // constructors ! ! public X509Certificate (byte[] data) ! { ! if (data != null) ! Parse (data); ! } ! ! private byte[] GetUnsignedBigInteger (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, 1, uinteger, 0, length); ! return uinteger; ! } ! else ! return integer; ! } ! ! // public methods ! ! public DSA DSA { ! get { ! DSAParameters dsaParams = new DSAParameters (); ! // for DSA m_publickey contains 1 ASN.1 integer - Y ! ASN1 pubkey = new ASN1 (m_publickey); ! if ((pubkey == null) || (pubkey.Tag != 0x02)) ! return null; ! dsaParams.Y = GetUnsignedBigInteger (pubkey.Value); ! ! ASN1 param = new ASN1 (m_keyalgoparams); ! if ((param == null) || (param.Tag != 0x30) || (param.Count < 3)) ! return null; ! if ((param [0].Tag != 0x02) || (param [1].Tag != 0x02) || (param [2].Tag != 0x02)) ! return null; ! dsaParams.P = GetUnsignedBigInteger (param [0].Value); ! dsaParams.Q = GetUnsignedBigInteger (param [1].Value); ! dsaParams.G = GetUnsignedBigInteger (param [2].Value); ! ! // BUG: MS BCL 1.0 can't import a key which ! // isn't the same size as the one present in ! // the container. ! DSACryptoServiceProvider dsa = new DSACryptoServiceProvider (dsaParams.Y.Length << 3); ! dsa.ImportParameters (dsaParams); ! return (DSA) dsa; ! } ! } ! ! public X509Extensions Extensions { ! get { return extensions; } ! } ! ! 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.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; ! } ! } ! } ! ! public virtual string IssuerName { ! get { return m_issuername; } ! } ! ! public virtual string KeyAlgorithm { ! get { return m_keyalgo; } ! } ! ! public virtual byte[] KeyAlgorithmParameters { ! get { return m_keyalgoparams; } ! } ! ! public virtual byte[] PublicKey { ! get { return m_publickey; } ! } ! ! public virtual RSA RSA { ! get { ! RSAParameters rsaParams = new RSAParameters (); ! // for RSA m_publickey contains 2 ASN.1 integers ! // the modulus and the public exponent ! ASN1 pubkey = new ASN1 (m_publickey); ! ASN1 modulus = pubkey [0]; ! if ((modulus == null) || (modulus.Tag != 0x02)) ! return null; ! ASN1 exponent = pubkey [1]; ! if (exponent.Tag != 0x02) ! return null; ! ! rsaParams.Modulus = GetUnsignedBigInteger (modulus.Value); ! rsaParams.Exponent = exponent.Value; ! ! // BUG: MS BCL 1.0 can't import a key which ! // isn't the same size as the one present in ! // the container. ! int keySize = (rsaParams.Modulus.Length << 3); ! RSACryptoServiceProvider rsa = new RSACryptoServiceProvider (keySize); ! rsa.ImportParameters (rsaParams); ! return (RSA)rsa; ! } ! } ! ! public virtual byte[] RawData { ! get { return (byte[]) m_encodedcert.Clone (); } ! } ! ! 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 ! case "1.2.840.113549.1.1.4": // MD5 with RSA encryption ! case "1.2.840.113549.1.1.5": // SHA-1 with RSA Encryption ! return signature; ! case "1.2.840.10040.4.3": // SHA-1 with DSA ! ASN1 sign = new ASN1 (signature); ! if ((sign == null) || (sign.Count != 2)) ! return null; ! // parts may be less than 20 bytes (i.e. first bytes were 0x00) ! byte[] part1 = sign [0].Value; ! 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); ! } ! } ! } ! ! public virtual string SignatureAlgorithm { ! get { return m_signaturealgo; } ! } ! ! public virtual byte[] SignatureAlgorithmParameters { ! get { return m_signaturealgoparams; } ! } ! ! public virtual string SubjectName { ! get { return m_subject; } ! } ! ! public virtual DateTime ValidFrom { ! get { return m_from; } ! } ! ! public virtual DateTime ValidUntil { ! get { return m_until; } ! } ! ! public int Version { ! get { return version; } ! } ! ! public bool IsCurrent { ! get { return WasCurrent (DateTime.UtcNow); } ! } ! ! 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 ! DSASignatureDeformatter v = new DSASignatureDeformatter (dsa); ! // only SHA-1 is supported ! v.SetHashAlgorithm ("SHA1"); ! return v.VerifySignature (this.Hash, this.Signature); ! } ! ! internal bool VerifySignature (RSA rsa) ! { ! RSAPKCS1SignatureDeformatter v = new RSAPKCS1SignatureDeformatter (rsa); ! switch (m_signaturealgo) { ! // MD2 with RSA encryption ! case "1.2.840.113549.1.1.2": ! // maybe someone installed MD2 ? ! v.SetHashAlgorithm ("MD2"); ! break; ! // MD5 with RSA encryption ! case "1.2.840.113549.1.1.4": ! v.SetHashAlgorithm ("MD5"); ! break; ! // SHA-1 with RSA Encryption ! case "1.2.840.113549.1.1.5": ! v.SetHashAlgorithm ("SHA1"); ! break; ! default: ! throw new CryptographicException ("Unsupported hash algorithm: " + m_signaturealgo); ! } ! return v.VerifySignature (this.Hash, this.Signature); ! } ! ! public bool VerifySignature (AsymmetricAlgorithm aa) ! { ! if (aa is RSA) ! return VerifySignature (aa as RSA); ! else if (aa is DSA) ! return VerifySignature (aa as DSA); ! else ! throw new NotSupportedException ("Unknown Asymmetric Algorithm " + aa.ToString ()); ! } ! ! public bool CheckSignature (byte[] hash, string hashAlgorithm, byte[] signature) ! { ! RSACryptoServiceProvider r = (RSACryptoServiceProvider) RSA; ! return r.VerifyHash (hash, hashAlgorithm, signature); ! } ! ! public bool IsSelfSigned { ! get { ! if (m_issuername == m_subject) ! return VerifySignature (RSA); ! else ! return false; ! } ! } ! } } --- 1,429 ---- ! // ! // X509Certificates.cs: Handles X.509 certificates. ! // ! // Author: ! // Sebastien Pouliot (spo...@mo...) ! // ! // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) ! // ! ! using System; ! using System.Security.Cryptography; ! using SSCX = System.Security.Cryptography.X509Certificates; ! using System.Text; ! ! namespace Mono.Security.X509 { ! ! // References: ! // a. Internet X.509 Public Key Infrastructure Certificate and CRL Profile ! // http://www.ietf.org/rfc/rfc3280.txt ! // b. ITU ASN.1 standards (free download) ! // http://www.itu.int/ITU-T/studygroups/com17/languages/ ! ! internal class X509Certificate { ! ! private ASN1 decoder; ! ! private byte[] m_encodedcert; ! private DateTime m_from; ! private DateTime m_until; ! private string m_issuername; ! private string m_keyalgo; ! private byte[] m_keyalgoparams; ! private string m_subject; ! private byte[] m_publickey; ! private byte[] signature; ! private string m_signaturealgo; ! private byte[] m_signaturealgoparams; ! ! // from http://www.ietf.org/rfc/rfc2459.txt ! // ! //Certificate ::= SEQUENCE { ! // tbsCertificate TBSCertificate, ! // signatureAlgorithm AlgorithmIdentifier, ! // signature BIT STRING } ! // ! //TBSCertificate ::= SEQUENCE { ! // version [0] Version DEFAULT v1, ! // serialNumber CertificateSerialNumber, ! // signature AlgorithmIdentifier, ! // issuer Name, ! // validity Validity, ! // subject Name, ! // subjectPublicKeyInfo SubjectPublicKeyInfo, ! // issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL, ! // -- If present, version shall be v2 or v3 ! // subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL, ! // -- If present, version shall be v2 or v3 ! // extensions [3] Extensions OPTIONAL ! // -- If present, version shall be v3 -- } ! private int version; ! private byte[] serialnumber; ! ! private byte[] issuerUniqueID; ! private byte[] subjectUniqueID; ! private X509Extensions extensions; ! ! // that's were the real job is! ! private void Parse (byte[] data) ! { ! string e = "Input data cannot be coded as a valid certificate."; ! try { ! decoder = new ASN1 (data); ! // Certificate ! if (decoder.Tag != 0x30) ! throw new CryptographicException (e); ! // Certificate / TBSCertificate ! if (decoder [0].Tag != 0x30) ! throw new CryptographicException (e); ! ! ASN1 tbsCertificate = decoder [0]; ! ! int tbs = 0; ! // Certificate / TBSCertificate / Version ! ASN1 v = decoder [0][tbs]; ! version = 1; // DEFAULT v1 ! if (v.Tag == 0xA0) { ! // version (optional) is present only in v2+ certs ! version += v.Value [0]; // zero based ! tbs++; ! } ! ! // Certificate / TBSCertificate / CertificateSerialNumber ! ASN1 sn = decoder [0][tbs++]; ! if (sn.Tag != 0x02) ! throw new CryptographicException (e); ! serialnumber = sn.Value; ! Array.Reverse (serialnumber, 0, serialnumber.Length); ! ! // Certificate / TBSCertificate / AlgorithmIdentifier ! ASN1 signatureAlgo = tbsCertificate.Element (tbs++, 0x30); ! ! ASN1 issuer = tbsCertificate.Element (tbs++, 0x30); ! m_issuername = X501.ToString (issuer); ! ! ASN1 validity = tbsCertificate.Element (tbs++, 0x30); ! ASN1 notBefore = validity [0]; ! m_from = ASN1Convert.ToDateTime (notBefore); ! ASN1 notAfter = validity [1]; ! m_until = ASN1Convert.ToDateTime (notAfter); ! ! ASN1 subject = tbsCertificate.Element (tbs++, 0x30); ! m_subject = X501.ToString (subject); ! ! ASN1 subjectPublicKeyInfo = tbsCertificate.Element (tbs++, 0x30); ! ! 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 ! ASN1 parameters = algorithm [1]; ! m_keyalgoparams = parameters.GetBytes (); ! ! ASN1 subjectPublicKey = subjectPublicKeyInfo.Element (1, 0x03); ! // we must drop th first byte (which is the number of unused bits ! // in the BITSTRING) ! int n = subjectPublicKey.Length - 1; ! m_publickey = new byte [n]; ! Array.Copy (subjectPublicKey.Value, 1, m_publickey, 0, n); ! ! // signature processing ! byte[] bitstring = decoder [2].Value; ! // 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) ! m_signaturealgoparams = parameters.GetBytes (); ! else ! m_signaturealgoparams = null; ! ! // Certificate / TBSCertificate / issuerUniqueID ! ASN1 issuerUID = tbsCertificate.Element (tbs, 0xA1); ! if (issuerUID != null) { ! tbs++; ! issuerUniqueID = issuerUID.Value; ! } ! ! // Certificate / TBSCertificate / subjectUniqueID ! ASN1 subjectUID = tbsCertificate.Element (tbs, 0xA2); ! if (subjectUID != null) { ! tbs++; ! subjectUniqueID = subjectUID.Value; ! } ! ! // Certificate / TBSCertificate / Extensions ! 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 ! m_encodedcert = (byte[]) data.Clone (); ! } ! catch { ! throw new CryptographicException (e); ! } ! } ! ! // constructors ! ! public X509Certificate (byte[] data) ! { ! if (data != null) ! Parse (data); ! } ! ! private byte[] GetUnsignedBigInteger (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, 1, uinteger, 0, length); ! return uinteger; ! } ! else ! return integer; ! } ! ! // public methods ! ! public DSA DSA { ! get { ! DSAParameters dsaParams = new DSAParameters (); ! // for DSA m_publickey contains 1 ASN.1 integer - Y ! ASN1 pubkey = new ASN1 (m_publickey); ! if ((pubkey == null) || (pubkey.Tag != 0x02)) ! return null; ! dsaParams.Y = GetUnsignedBigInteger (pubkey.Value); ! ! ASN1 param = new ASN1 (m_keyalgoparams); ! if ((param == null) || (param.Tag != 0x30) || (param.Count < 3)) ! return null; ! if ((param [0].Tag != 0x02) || (param [1].Tag != 0x02) || (param [2].Tag != 0x02)) ! return null; ! dsaParams.P = GetUnsignedBigInteger (param [0].Value); ! dsaParams.Q = GetUnsignedBigInteger (param [1].Value); ! dsaParams.G = GetUnsignedBigInteger (param [2].Value); ! ! // BUG: MS BCL 1.0 can't import a key which ! // isn't the same size as the one present in ! // the container. ! DSACryptoServiceProvider dsa = new DSACryptoServiceProvider (dsaParams.Y.Length << 3); ! dsa.ImportParameters (dsaParams); ! return (DSA) dsa; ! } ! } ! ! public X509Extensions Extensions { ! get { return extensions; } ! } ! ! 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.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; ! } ! } ! } ! ! public virtual string IssuerName { ! get { return m_issuername; } ! } ! ! public virtual string KeyAlgorithm { ! get { return m_keyalgo; } ! } ! ! public virtual byte[] KeyAlgorithmParameters { ! get { return m_keyalgoparams; } ! } ! ! public virtual byte[] PublicKey { ! get { return m_publickey; } ! } ! ! public virtual RSA RSA { ! get { ! RSAParameters rsaParams = new RSAParameters (); ! // for RSA m_publickey contains 2 ASN.1 integers ! // the modulus and the public exponent ! ASN1 pubkey = new ASN1 (m_publickey); ! ASN1 modulus = pubkey [0]; ! if ((modulus == null) || (modulus.Tag != 0x02)) ! return null; ! ASN1 exponent = pubkey [1]; ! if (exponent.Tag != 0x02) ! return null; ! ! rsaParams.Modulus = GetUnsignedBigInteger (modulus.Value); ! rsaParams.Exponent = exponent.Value; ! ! // BUG: MS BCL 1.0 can't import a key which ! // isn't the same size as the one present in ! // the container. ! int keySize = (rsaParams.Modulus.Length << 3); ! RSACryptoServiceProvider rsa = new RSACryptoServiceProvider (keySize); ! rsa.ImportParameters (rsaParams); ! return (RSA)rsa; ! } ! } ! ! public virtual byte[] RawData { ! get { return (byte[]) m_encodedcert.Clone (); } ! } ! ! 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 ! case "1.2.840.113549.1.1.4": // MD5 with RSA encryption ! case "1.2.840.113549.1.1.5": // SHA-1 with RSA Encryption ! return signature; ! case "1.2.840.10040.4.3": // SHA-1 with DSA ! ASN1 sign = new ASN1 (signature); ! if ((sign == null) || (sign.Count != 2)) ! return null; ! // parts may be less than 20 bytes (i.e. first bytes were 0x00) ! byte[] part1 = sign [0].Value; ! 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); ! } ! } ! } ! ! public virtual string SignatureAlgorithm { ! get { return m_signaturealgo; } ! } ! ! public virtual byte[] SignatureAlgorithmParameters { ! get { return m_signaturealgoparams; } ! } ! ! public virtual string SubjectName { ! get { return m_subject; } ! } ! ! public virtual DateTime ValidFrom { ! get { return m_from; } ! } ! ! public virtual DateTime ValidUntil { ! get { return m_until; } ! } ! ! public int Version { ! get { return version; } ! } ! ! public bool IsCurrent { ! get { return WasCurrent (DateTime.UtcNow); } ! } ! ! 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 ! DSASignatureDeformatter v = new DSASignatureDeformatter (dsa); ! // only SHA-1 is supported ! v.SetHashAlgorithm ("SHA1"); ! return v.VerifySignature (this.Hash, this.Signature); ! } ! ! internal bool VerifySignature (RSA rsa) ! { ! RSAPKCS1SignatureDeformatter v = new RSAPKCS1SignatureDeformatter (rsa); ! switch (m_signaturealgo) { ! // MD2 with RSA encryption ! case "1.2.840.113549.1.1.2": ! // maybe someone installed MD2 ? ! v.SetHashAlgorithm ("MD2"); ! break; ! // MD5 with RSA encryption ! case "1.2.840.113549.1.1.4": ! v.SetHashAlgorithm ("MD5"); ! break; ! // SHA-1 with RSA Encryption ! case "1.2.840.113549.1.1.5": ! v.SetHashAlgorithm ("SHA1"); ! break; ! default: ! throw new CryptographicException ("Unsupported hash algorithm: " + m_signaturealgo); ! } ! return v.VerifySignature (this.Hash, this.Signature); ! } ! ! public bool VerifySignature (AsymmetricAlgorithm aa) ! { ! if (aa is RSA) ! return VerifySignature (aa as RSA); ! else if (aa is DSA) ! return VerifySignature (aa as DSA); ! else ! throw new NotSupportedException ("Unknown Asymmetric Algorithm " + aa.ToString ()); ! } ! ! public bool CheckSignature (byte[] hash, string hashAlgorithm, byte[] signature) ! { ! RSACryptoServiceProvider r = (RSACryptoServiceProvider) RSA; ! return r.VerifyHash (hash, hashAlgorithm, signature); ! } ! ! public bool IsSelfSigned { ! get { ! if (m_issuername == m_subject) ! return VerifySignature (RSA); ! else ! return false; ! } ! } ! } } |
|
From: <car...@us...> - 2003-12-26 11:14:29
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls In directory sc8-pr-cvs1:/tmp/cvs-serv32132 Modified Files: TlsCipherSuiteFactory.cs Log Message: Minor change Index: TlsCipherSuiteFactory.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/TlsCipherSuiteFactory.cs,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** TlsCipherSuiteFactory.cs 21 Dec 2003 14:38:27 -0000 1.15 --- TlsCipherSuiteFactory.cs 26 Dec 2003 11:14:26 -0000 1.16 *************** *** 51,55 **** // Supported ciphers - scs.Add((0x00 << 0x08) | 0x35, "TLS_RSA_WITH_AES_256_CBC_SHA", CipherAlgorithmType.Rijndael, HashAlgorithmType.Sha1, ExchangeAlgorithmType.RsaSign, false, true, 32, 32, 256, 16, 16); scs.Add((0x00 << 0x08) | 0x2F, "TLS_RSA_WITH_AES_128_CBC_SHA", CipherAlgorithmType.Rijndael, HashAlgorithmType.Sha1, ExchangeAlgorithmType.RsaSign, false, true, 16, 16, 128, 16, 16); --- 51,54 ---- |
|
From: <car...@us...> - 2003-12-23 18:26:36
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls In directory sc8-pr-cvs1:/tmp/cvs-serv28227 Modified Files: changelog.txt Log Message: 2003-12-23 Carlos Guzmán Álvarez <car...@te...> * Mono.Security.Protocol.Tls/SslClientStream.cs: - Try to improve record reading. Index: changelog.txt =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/changelog.txt,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** changelog.txt 21 Dec 2003 14:56:59 -0000 1.18 --- changelog.txt 23 Dec 2003 18:26:33 -0000 1.19 *************** *** 3,6 **** --- 3,12 ---- + 2003-12-23 Carlos Guzmán Álvarez <car...@te...> + + * Mono.Security.Protocol.Tls/SslClientStream.cs: + + - Try to improve record reading. + 2003-12-21 Carlos Guzmán Álvarez <car...@te...> |
|
From: <car...@us...> - 2003-12-23 18:26:18
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls
In directory sc8-pr-cvs1:/tmp/cvs-serv28189
Modified Files:
SslClientStream.cs
Log Message:
2003-12-23 Carlos Guzmán Álvarez <car...@te...>
* Mono.Security.Protocol.Tls/SslClientStream.cs:
- Try to improve record reading.
Index: SslClientStream.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/SslClientStream.cs,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** SslClientStream.cs 21 Dec 2003 14:36:14 -0000 1.11
--- SslClientStream.cs 23 Dec 2003 18:26:14 -0000 1.12
***************
*** 498,503 ****
long position = this.inputBuffer.Position;
byte[] record = this.receiveRecord();
!
! if (record.Length > 0)
{
// Write new data to the inputBuffer
--- 498,504 ----
long position = this.inputBuffer.Position;
byte[] record = this.receiveRecord();
!
! if (record != null &&
! record.Length > 0)
{
// Write new data to the inputBuffer
***************
*** 508,511 ****
--- 509,519 ----
this.inputBuffer.Seek(position, SeekOrigin.Begin);
}
+ else
+ {
+ if (record == null)
+ {
+ break;
+ }
+ }
}
***************
*** 614,618 ****
}
! TlsContentType contentType = (TlsContentType)innerStream.ReadByte();
SecurityProtocolType protocol = (SecurityProtocolType)this.ReadShort();
short length = this.ReadShort();
--- 622,635 ----
}
! // Try to read the Record Content Type
! int type = innerStream.ReadByte();
!
! // There are no more data for read
! if (type == -1)
! {
! return null;
! }
!
! TlsContentType contentType = (TlsContentType)type;
SecurityProtocolType protocol = (SecurityProtocolType)this.ReadShort();
short length = this.ReadShort();
|
|
From: <car...@us...> - 2003-12-23 18:24:26
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls
In directory sc8-pr-cvs1:/tmp/cvs-serv27874
Modified Files:
RSASslSignatureDeformatter.cs RSASslSignatureFormatter.cs
Log Message:
Changed to internal
Index: RSASslSignatureDeformatter.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/RSASslSignatureDeformatter.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** RSASslSignatureDeformatter.cs 21 Dec 2003 14:33:04 -0000 1.2
--- RSASslSignatureDeformatter.cs 23 Dec 2003 18:24:23 -0000 1.3
***************
*** 28,32 ****
namespace Mono.Security.Protocol.Tls
{
! public class RSASslSignatureDeformatter : AsymmetricSignatureDeformatter
{
#region Fields
--- 28,32 ----
namespace Mono.Security.Protocol.Tls
{
! internal class RSASslSignatureDeformatter : AsymmetricSignatureDeformatter
{
#region Fields
Index: RSASslSignatureFormatter.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/RSASslSignatureFormatter.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** RSASslSignatureFormatter.cs 21 Dec 2003 14:33:04 -0000 1.2
--- RSASslSignatureFormatter.cs 23 Dec 2003 18:24:23 -0000 1.3
***************
*** 28,32 ****
namespace Mono.Security.Protocol.Tls
{
! public class RSASslSignatureFormatter : AsymmetricSignatureFormatter
{
#region Fields
--- 28,32 ----
namespace Mono.Security.Protocol.Tls
{
! internal class RSASslSignatureFormatter : AsymmetricSignatureFormatter
{
#region Fields
|
|
From: <car...@us...> - 2003-12-22 09:32:14
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10
In directory sc8-pr-cvs1:/tmp/cvs-serv2308
Modified Files:
makefile
Log Message:
Updated linux makefile
Index: makefile
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/makefile,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** makefile 11 Oct 2003 10:00:24 -0000 1.8
--- makefile 22 Dec 2003 09:32:10 -0000 1.9
***************
*** 1,48 ****
! TLS = Mono.Security.Tls.dll
! LIBRARY = PostgreSql.Data.PgSqlClient.dll
! NUNIT_SUITE = PostgreSql.Data.PgSqlClient.UnitTests.dll
!
! all: ${TLS} $(LIBRARY) $(NUNIT_SUITE) install clean
!
! CSC = mcs
! COPY = cp
!
! # References to assemblies
! LD_BASIC_FLAGS = -reference:System.dll -reference:System.Data.dll -reference:System.Drawing.dll -reference:System.Xml.dll
! LD_FLAGS = -reference:System.dll -reference:System.Design.dll -reference:System.Data.dll -reference:System.Drawing.dll -reference:System.Xml.dll
!
! # Resources for the Toolbox
! TOOL_RESOURCES = -resource:PostgreSql.Data.PgSqlClient/source/Resources/ToolBox/PgConnection.bmp,PostgreSql.Data.PgSqlClient.Resources.ToolBox.PgConnection.bmp -resource:PostgreSql.Data.PgSqlClient/source/Resources/ToolBox/PgCommand.bmp,PostgreSql.Data.PgSqlClient.Resources.ToolBox.PgCommand.bmp -resource:PostgreSql.Data.PgSqlClient/source/Resources/ToolBox/PgDataAdapter.bmp,PostgreSql.Data.PgSqlClient.Resources.ToolBox.PgDataAdapter.bmp
!
! # Source files
! RECURSE_TLS = -recurse:./PgSqlClient.Security.Tls/source/*.cs
! RECURSE_SOURCE = -recurse:./PostgreSql.Data.PgSqlClient/source/*.cs
! RECURSE_TESTS = -recurse:./PostgreSql.Data.PgSqlClient.UnitTests/source/*.cs
!
! # COnfiguration files
! NUNIT_CONFIG=./PostgreSql.Data.PgSqlClient.UnitTests/PostgreSql.Data.PgSqlClient.UnitTests.dll.config
!
! # Defines
! DEFINE = -define:_DEBUG
!
! Mono.Security.Tls.dll:
! $(CSC) -target:library -out:$(TLS) $(LD_BASIC_FLAGS) $(DEFINE) $(RECURSE_TLS)
!
! PostgreSql.Data.PgSqlClient.dll:
! $(CSC) -target:library -out:$(LIBRARY) $(LD_FLAGS) -reference:Mono.Security.Tls.dll $(DEFINE) $(TOOL_RESOURCES) $(RECURSE_SOURCE)
!
! PostgreSql.Data.PgSqlClient.UnitTests.dll:
! $(CSC) -target:library -out:$(NUNIT_SUITE) $(LD_BASIC_FLAGS) -reference:${LIBRARY} -reference:NUnit.Framework.dll $(DEFINE) $(TOOL_RESOURCES) $(RECURSE_TESTS)
!
! install:
! rm -rf build
! mkdir -p build
! $(COPY) $(TLS) ./build
! $(COPY) $(LIBRARY) ./build
! $(COPY) $(NUNIT_SUITE) ./build
! $(COPY) ${NUNIT_CONFIG} ./build
!
! clean:
! rm $(TLS)
rm $(LIBRARY)
rm ${NUNIT_SUITE}
--- 1,48 ----
! TLS = Mono.Security.Tls.dll
! LIBRARY = PostgreSql.Data.PgSqlClient.dll
! NUNIT_SUITE = PostgreSql.Data.PgSqlClient.UnitTests.dll
!
! all: ${TLS} $(LIBRARY) $(NUNIT_SUITE) install clean
!
! CSC = mcs
! COPY = cp
!
! # References to assemblies
! LD_BASIC_FLAGS = -reference:System.dll -reference:System.Data.dll -reference:System.Drawing.dll -reference:System.Xml.dll
! LD_FLAGS = -reference:System.dll -reference:System.Design.dll -reference:System.Data.dll -reference:System.Drawing.dll -reference:System.Xml.dll
!
! # Resources for the Toolbox
! TOOL_RESOURCES = -resource:PostgreSql.Data.PgSqlClient/source/Resources/ToolBox/PgConnection.bmp,PostgreSql.Data.PgSqlClient.Resources.ToolBox.PgConnection.bmp -resource:PostgreSql.Data.PgSqlClient/source/Resources/ToolBox/PgCommand.bmp,PostgreSql.Data.PgSqlClient.Resources.ToolBox.PgCommand.bmp -resource:PostgreSql.Data.PgSqlClient/source/Resources/ToolBox/PgDataAdapter.bmp,PostgreSql.Data.PgSqlClient.Resources.ToolBox.PgDataAdapter.bmp
!
! # Source files
! RECURSE_TLS = -recurse:./Mono.Security.Protocol.Tls//*.cs
! RECURSE_SOURCE = -recurse:./PostgreSql.Data.PgSqlClient/source/*.cs
! RECURSE_TESTS = -recurse:./PostgreSql.Data.PgSqlClient.UnitTests/source/*.cs
!
! # COnfiguration files
! NUNIT_CONFIG=./PostgreSql.Data.PgSqlClient.UnitTests/PostgreSql.Data.PgSqlClient.UnitTests.dll.config
!
! # Defines
! DEFINE = -define:_DEBUG
!
! Mono.Security.Tls.dll:
! $(CSC) -target:library -out:$(TLS) $(LD_BASIC_FLAGS) $(DEFINE) $(RECURSE_TLS)
!
! PostgreSql.Data.PgSqlClient.dll:
! $(CSC) -target:library -out:$(LIBRARY) $(LD_FLAGS) -reference:Mono.Security.Tls.dll $(DEFINE) $(TOOL_RESOURCES) $(RECURSE_SOURCE)
!
! PostgreSql.Data.PgSqlClient.UnitTests.dll:
! $(CSC) -target:library -out:$(NUNIT_SUITE) $(LD_BASIC_FLAGS) -reference:${LIBRARY} -reference:NUnit.Framework.dll $(DEFINE) $(TOOL_RESOURCES) $(RECURSE_TESTS)
!
! install:
! rm -rf build
! mkdir -p build
! $(COPY) $(TLS) ./build
! $(COPY) $(LIBRARY) ./build
! $(COPY) $(NUNIT_SUITE) ./build
! $(COPY) ${NUNIT_CONFIG} ./build
!
! clean:
! rm $(TLS)
rm $(LIBRARY)
rm ${NUNIT_SUITE}
|
|
From: <car...@us...> - 2003-12-21 14:57:03
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls In directory sc8-pr-cvs1:/tmp/cvs-serv8068 Modified Files: changelog.txt Log Message: 2003-12-21 Carlos Guzmán Álvarez <car...@te...> * Mono.Security.Protocol.Tls.Handshake.Client/TlsClientCertificate.cs: - Send always the first certificate. * Mono.Security.Protocol.Tls.Handshake.Client/TlsServerKeyExchange.cs: - Added changes for correct verification of the signed data sent by the server. * Mono.Security.Cryptography/PKCS1.cs: - Added change to Encode_v15 method for allow correct encoding of hash algorithms that doesn't have an OID like the MD5SHA1 hash used in SSL/TLS protocols. * Added files from mono:: project that are going to be needed for client authentication: Mono.Math/* Mono.Math.Prime/* Mono.Math.Prime.Generator/* Mono.Security.Cryptography/RSAManaged.cs * Mono.Security.Protocol.Tls/RSASslSignatureFormatter.cs: - Create RSA as an RSAManaged instance. * Mono.Security.Protocol.Tls/RSASslSignatureFormatter.cs: * Mono.Security.Protocol.Tls/RSASslSignatureDeformatter.cs: - Changed key field to be of RSA type. Index: changelog.txt =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/changelog.txt,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** changelog.txt 18 Dec 2003 10:10:17 -0000 1.17 --- changelog.txt 21 Dec 2003 14:56:59 -0000 1.18 *************** *** 2,5 **** --- 2,43 ---- --------------- ----------- ----------------------------------------- + + 2003-12-21 Carlos Guzmán Álvarez <car...@te...> + + * Mono.Security.Protocol.Tls.Handshake.Client/TlsClientCertificate.cs: + + - Send always the first certificate. + + * Mono.Security.Protocol.Tls.Handshake.Client/TlsServerKeyExchange.cs: + + - Added changes for correct verification of the signed data sent + by the server. + + * Mono.Security.Cryptography/PKCS1.cs: + + - Added change to Encode_v15 method for allow correct + encoding of hash algorithms that doesn't have an OID + like the MD5SHA1 hash used in SSL/TLS protocols. + + * Added files from mono:: project that are going to be needed + for client authentication: + + Mono.Math/* + + Mono.Math.Prime/* + + Mono.Math.Prime.Generator/* + + Mono.Security.Cryptography/RSAManaged.cs + + * Mono.Security.Protocol.Tls/RSASslSignatureFormatter.cs: + + - Create RSA as an RSAManaged instance. + + * Mono.Security.Protocol.Tls/RSASslSignatureFormatter.cs: + * Mono.Security.Protocol.Tls/RSASslSignatureDeformatter.cs: + + - Changed key field to be of RSA type. + 2003-12-14 Carlos Guzmán Álvarez <car...@te...> |
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls.Handshake/Mono.Security.Protocol.Tls.Handshake.Client
In directory sc8-pr-cvs1:/tmp/cvs-serv7974
Modified Files:
TlsClientCertificate.cs TlsServerKeyExchange.cs
Log Message:
2003-12-21 Carlos Guzmán Álvarez <car...@te...>
* Mono.Security.Protocol.Tls.Handshake.Client/TlsClientCertificate.cs:
- Send always the first certificate.
* Mono.Security.Protocol.Tls.Handshake.Client/TlsServerKeyExchange.cs:
- Added changes for correct verification of the signed data sent
by the server.
Index: TlsClientCertificate.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls.Handshake/Mono.Security.Protocol.Tls.Handshake.Client/TlsClientCertificate.cs,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** TlsClientCertificate.cs 14 Dec 2003 15:01:54 -0000 1.12
--- TlsClientCertificate.cs 21 Dec 2003 14:56:06 -0000 1.13
***************
*** 24,30 ****
using System;
- using Mono.Security.Protocol.Tls;
using System.Security.Cryptography.X509Certificates;
namespace Mono.Security.Protocol.Tls.Handshake.Client
{
--- 24,31 ----
using System;
using System.Security.Cryptography.X509Certificates;
+ using Mono.Security.Protocol.Tls;
+
namespace Mono.Security.Protocol.Tls.Handshake.Client
{
***************
*** 65,75 ****
}
// Write client certificates information to a stream
TlsStream stream = new TlsStream();
! foreach (X509Certificate cert in this.Context.ClientSettings.Certificates)
! {
! stream.WriteInt24(cert.GetRawCertData().Length);
! stream.Write(cert.GetRawCertData());
! }
// Compose the message
--- 66,86 ----
}
+ // Select a valid certificate
+ X509Certificate clientCert = this.Context.ClientSettings.Certificates[0];
+
+ /*
+ clientCert = this.Context.SslStream.RaiseClientCertificateSelection(
+ this.Context.ClientSettings.Certificates,
+ this.Context.ServerSettings.Certificates[0],
+ this.Context.ClientSettings.TargetHost,
+ null);
+ */
+
+
// Write client certificates information to a stream
TlsStream stream = new TlsStream();
!
! stream.WriteInt24(clientCert.GetRawCertData().Length);
! stream.Write(clientCert.GetRawCertData());
// Compose the message
Index: TlsServerKeyExchange.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls.Handshake/Mono.Security.Protocol.Tls.Handshake.Client/TlsServerKeyExchange.cs,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** TlsServerKeyExchange.cs 14 Dec 2003 15:01:54 -0000 1.15
--- TlsServerKeyExchange.cs 21 Dec 2003 14:56:06 -0000 1.16
***************
*** 37,40 ****
--- 37,41 ----
private RSAParameters rsaParams;
private byte[] signedParams;
+ private byte[] content;
#endregion
***************
*** 92,103 ****
MD5SHA1 hash = new MD5SHA1();
// Create server params array
TlsStream stream = new TlsStream();
stream.Write(this.Context.RandomCS);
! stream.Write(rsaParams.Modulus.Length);
! stream.Write(rsaParams.Modulus);
! stream.Write(rsaParams.Exponent.Length);
! stream.Write(rsaParams.Exponent);
hash.ComputeHash(stream.ToArray());
--- 93,104 ----
MD5SHA1 hash = new MD5SHA1();
+ // Calculate size of server params
+ int size = rsaParams.Modulus.Length + rsaParams.Exponent.Length + 4;
+
// Create server params array
TlsStream stream = new TlsStream();
stream.Write(this.Context.RandomCS);
! stream.Write(this.ToArray(), 0, size);
hash.ComputeHash(stream.ToArray());
***************
*** 105,111 ****
stream.Reset();
! hash.VerifySignature(
this.Context.Cipher.CertificateRSA(),
this.signedParams);
}
--- 106,117 ----
stream.Reset();
! bool isValidSignature = hash.VerifySignature(
this.Context.Cipher.CertificateRSA(),
this.signedParams);
+
+ if (!isValidSignature)
+ {
+ throw this.Context.CreateException("Data was not signed with the server certificate.");
+ }
}
|
|
From: <car...@us...> - 2003-12-21 14:52:06
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Security/Mono.Security.Cryptography
In directory sc8-pr-cvs1:/tmp/cvs-serv7195
Modified Files:
PKCS1.cs
Log Message:
2003-12-21 Carlos Guzmán Álvarez <car...@te...>
* Mono.Security.Cryptography/PKCS1.cs:
- Added change to Encode_v15 method for allow correct
encoding of hash algorithms that doesn't have an OID
like the MD5SHA1 hash used in SSL/TLS protocols.
Index: PKCS1.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/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 14 Dec 2003 15:01:08 -0000 1.1
--- PKCS1.cs 21 Dec 2003 14:52:03 -0000 1.2
***************
*** 291,310 ****
// digest OCTET STRING
// }
! /*
! string oid = CryptoConfig.MapNameToOID (hash.ToString ());
! ASN1 digestAlgorithm = new ASN1 (0x30);
! digestAlgorithm.Add (new ASN1 (CryptoConfig.EncodeOID (oid)));
! digestAlgorithm.Add (new ASN1 (0x05)); // NULL
! ASN1 digest = new ASN1 (0x04, hashValue);
! ASN1 digestInfo = new ASN1 (0x30);
! digestInfo.Add (digestAlgorithm);
! digestInfo.Add (digest);
! byte[] t = digestInfo.GetBytes ();
! */
! ASN1 digestInfo = new ASN1 (0x30);
! digestInfo.Add (new ASN1 (0x04, hashValue));
! byte[] t = digestInfo.GetBytes();
Array.Copy (hashValue, 0, t, t.Length - hashValue.Length, hashValue.Length);
--- 291,316 ----
// digest OCTET STRING
// }
!
! byte[] t = null;
! string oid = CryptoConfig.MapNameToOID (hash.ToString ());
! if (oid != null)
! {
! ASN1 digestAlgorithm = new ASN1 (0x30);
! digestAlgorithm.Add (new ASN1 (CryptoConfig.EncodeOID (oid)));
! digestAlgorithm.Add (new ASN1 (0x05)); // NULL
! ASN1 digest = new ASN1 (0x04, hashValue);
! ASN1 digestInfo = new ASN1 (0x30);
! digestInfo.Add (digestAlgorithm);
! digestInfo.Add (digest);
! t = digestInfo.GetBytes ();
! }
! else
! {
! // There are no valid OID, in this case t = hashValue
! // This is the case of the MD5SHA hash algorithm
! t = hashValue;
! }
Array.Copy (hashValue, 0, t, t.Length - hashValue.Length, hashValue.Length);
|
|
From: <car...@us...> - 2003-12-21 14:43:04
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Security/Mono.Security.Cryptography In directory sc8-pr-cvs1:/tmp/cvs-serv2805 Added Files: RSAManaged.cs Log Message: 2003-12-21 Carlos Guzmán Álvarez <car...@te...> * Added files from mono:: project that are going to be needed for client authentication: Mono.Math/* Mono.Math.Prime/* Mono.Math.Prime.Generator/* Mono.Security.Cryptography/RSAManaged.cs --- NEW FILE: RSAManaged.cs --- // // RSAManaged.cs - Implements the RSA algorithm. // // 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/) // See bouncycastle.txt for license. // using System; using System.Security.Cryptography; using Mono.Math; // Big chunks of code are coming from the original RSACryptoServiceProvider class. // The class was refactored to : // a. ease integration of new hash algorithm (like MD2, RIPEMD160, ...); // b. provide better support for the coming SSL implementation (requires // EncryptValue/DecryptValue) with, or without, Mono runtime/corlib; // c. provide an alternative RSA implementation for all Windows (like using // OAEP without Windows XP). namespace Mono.Security.Cryptography { internal class RSAManaged : RSA { private const int defaultKeySize = 1024; private bool isCRTpossible = false; private bool keypairGenerated = false; private bool m_disposed = false; private BigInteger d; private BigInteger p; private BigInteger q; private BigInteger dp; private BigInteger dq; private BigInteger qInv; private BigInteger n; // modulus private BigInteger e; public RSAManaged () : this (defaultKeySize) {} public RSAManaged (int dwKeySize) { KeySizeValue = dwKeySize; LegalKeySizesValue = new KeySizes [1]; LegalKeySizesValue [0] = new KeySizes (384, 16384, 8); } ~RSAManaged () { // Zeroize private key Dispose (false); } private void GenerateKeyPair () { // p and q values should have a length of half the strength in bits int pbitlength = ((KeySize + 1) >> 1); int qbitlength = (KeySize - pbitlength); const uint uint_e = 17; e = uint_e; // fixed // generate p, prime and (p-1) relatively prime to e for (;;) { p = BigInteger.genPseudoPrime (pbitlength); if (p % uint_e != 1) break; } // generate a modulus of the required length for (;;) { // generate q, prime and (q-1) relatively prime to e, // and not equal to p for (;;) { q = BigInteger.genPseudoPrime (qbitlength); if ((q % uint_e != 1) && (p != q)) break; } // calculate the modulus n = p * q; if (n.bitCount () == KeySize) break; // if we get here our primes aren't big enough, make the largest // of the two p and try again if (p < q) p = q; } BigInteger pSub1 = (p - 1); BigInteger qSub1 = (q - 1); BigInteger phi = pSub1 * qSub1; // calculate the private exponent d = e.modInverse (phi); // calculate the CRT factors dp = d % pSub1; dq = d % qSub1; qInv = q.modInverse (p); keypairGenerated = true; isCRTpossible = true; } // overrides from RSA class public override int KeySize { get { // in case keypair hasn't been (yet) generated if (keypairGenerated) return n.bitCount (); else return base.KeySize; } } public override string KeyExchangeAlgorithm { get { return "RSA-PKCS1-KeyEx"; } } public override string SignatureAlgorithm { get { return "http://www.w3.org/2000/09/xmldsig#rsa-sha1"; } } public override byte[] DecryptValue (byte[] rgb) { if (m_disposed) throw new ObjectDisposedException ("private key"); // decrypt operation is used for signature if (!keypairGenerated) GenerateKeyPair (); BigInteger input = new BigInteger (rgb); BigInteger output; // decrypt (which uses the private key) can be // optimized by using CRT (Chinese Remainder Theorem) 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) { // thanks to benm! h = p - ((m2 - m1) * qInv % p); output = m2 + q * h; } else { // h = (m1 - m2) * qInv mod p h = (m1 - m2) * qInv % p; // m = m2 + q * h; output = m2 + q * h; } } else { // m = c^d mod n output = input.modPow (d, n); } byte[] result = output.getBytes (); // zeroize value input.Clear (); output.Clear (); return result; } public override byte[] EncryptValue (byte[] rgb) { if (m_disposed) throw new ObjectDisposedException ("public key"); if (!keypairGenerated) GenerateKeyPair (); BigInteger input = new BigInteger (rgb); BigInteger output = input.modPow (e, n); byte[] result = output.getBytes (); // zeroize value input.Clear (); output.Clear (); return result; } public override RSAParameters ExportParameters (bool includePrivateParameters) { if (m_disposed) throw new ObjectDisposedException (""); if (!keypairGenerated) GenerateKeyPair (); 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; } public override void ImportParameters (RSAParameters parameters) { if (m_disposed) throw new ObjectDisposedException (""); // if missing "mandatory" parameters if (parameters.Exponent == null) throw new CryptographicException ("Missing Exponent"); if (parameters.Modulus == null) throw new CryptographicException ("Missing Modulus"); e = new BigInteger (parameters.Exponent); n = new BigInteger (parameters.Modulus); // only if the private key is present if (parameters.D != null) d = new BigInteger (parameters.D); if (parameters.DP != null) dp = new BigInteger (parameters.DP); if (parameters.DQ != null) dq = new BigInteger (parameters.DQ); if (parameters.InverseQ != null) qInv = new BigInteger (parameters.InverseQ); if (parameters.P != null) p = new BigInteger (parameters.P); if (parameters.Q != null) q = new BigInteger (parameters.Q); // we now have a keypair keypairGenerated = true; isCRTpossible = ((p != null) && (q != null) && (dp != null) && (dq != null) && (qInv != null)); } protected override void Dispose (bool disposing) { if (!m_disposed) { // Always zeroize private key if (d != null) { d.Clear (); d = null; } if (p != null) { p.Clear (); p = null; } if (q != null) { q.Clear (); q = null; } if (dp != null) { dp.Clear (); dp = null; } if (dq != null) { dq.Clear (); dq = null; } if (qInv != null) { qInv.Clear (); qInv = null; } if (disposing) { // clear public key if (e != null) { e.Clear (); e = null; } if (n != null) { n.Clear (); n = null; } } } // call base class // no need as they all are abstract before us m_disposed = true; } } } |
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Math.Prime.Generator
In directory sc8-pr-cvs1:/tmp/cvs-serv2773
Added Files:
NextPrimeFinder.cs PrimeGeneratorBase.cs
SequentialSearchPrimeGeneratorBase.cs
Log Message:
2003-12-21 Carlos Guzmán Álvarez <car...@te...>
* Added files from mono:: project that are going to be needed
for client authentication:
Mono.Math/*
Mono.Math.Prime/*
Mono.Math.Prime.Generator/*
Mono.Security.Cryptography/RSAManaged.cs
--- NEW FILE: NextPrimeFinder.cs ---
//
// Mono.Math.Prime.Generator.NextPrimeFinder.cs - Prime Generator
//
// Authors:
// Ben Maurer
//
// Copyright (c) 2003 Ben Maurer. All rights reserved
//
using System;
namespace Mono.Math.Prime.Generator {
/// <summary>
/// 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;
}
}
}
--- NEW FILE: PrimeGeneratorBase.cs ---
//
// Mono.Math.Prime.Generator.PrimeGeneratorBase.cs - Abstract Prime Generator
//
// Authors:
// Ben Maurer
//
// Copyright (c) 2003 Ben Maurer. All rights reserved
//
using System;
namespace Mono.Math.Prime.Generator {
[CLSCompliant(false)]
internal abstract class PrimeGeneratorBase {
public virtual ConfidenceFactor Confidence {
get {
#if DEBUG
return ConfidenceFactor.ExtraLow;
#else
return ConfidenceFactor.Medium;
#endif
}
}
public virtual Prime.PrimalityTest PrimalityTest {
get {
return new Prime.PrimalityTest (PrimalityTests.SmallPrimeSppTest);
}
}
public virtual int TrialDivisionBounds {
get { return 4000; }
}
/// <summary>
/// Performs primality tests on bi, assumes trial division has been done.
/// </summary>
/// <param name="bi">A BigInteger that has been subjected to and passed trial division</param>
/// <returns>False if bi is composite, true if it may be prime.</returns>
/// <remarks>The speed of this method is dependent on Confidence</remarks>
protected bool PostTrialDivisionTests (BigInteger bi)
{
return PrimalityTest (bi, this.Confidence);
}
public abstract BigInteger GenerateNewPrime (int bits);
}
}
--- NEW FILE: SequentialSearchPrimeGeneratorBase.cs ---
//
// Mono.Math.Prime.Generator.SequentialSearchPrimeGeneratorBase.cs - Prime Generator
//
// Authors:
// Ben Maurer
//
// Copyright (c) 2003 Ben Maurer. All rights reserved
//
using System;
using Mono.Math.Prime;
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;
}
public override BigInteger GenerateNewPrime (int bits)
{
return GenerateNewPrime (bits, null);
}
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;
uint pMod1 = curVal % primeProd1;
int DivisionBound = TrialDivisionBounds;
uint[] SmallPrimes = BigInteger.smallPrimes;
PrimalityTest PostTrialDivisionTest = this.PrimalityTest;
//
// STEP 2. Search for primes
//
while (true) {
//
// STEP 2.1 Sieve out numbers divisible by the first 9 primes
//
if (pMod1 % 3 == 0) goto biNotPrime;
if (pMod1 % 5 == 0) goto biNotPrime;
if (pMod1 % 7 == 0) goto biNotPrime;
if (pMod1 % 11 == 0) goto biNotPrime;
if (pMod1 % 13 == 0) goto biNotPrime;
if (pMod1 % 17 == 0) goto biNotPrime;
if (pMod1 % 19 == 0) goto biNotPrime;
if (pMod1 % 23 == 0) goto biNotPrime;
if (pMod1 % 29 == 0) goto biNotPrime;
//
// STEP 2.2 Sieve out all numbers divisible by the primes <= DivisionBound
//
for (int p = 9; p < SmallPrimes.Length && SmallPrimes [p] <= DivisionBound; p++) {
if (curVal % SmallPrimes [p] == 0)
goto biNotPrime;
}
//
// STEP 2.3 Is the potential prime acceptable?
//
if (!IsPrimeAcceptable (curVal, Context)) goto biNotPrime;
//
// STEP 2.4 Filter out all primes that pass this step with a primality test
//
if (PrimalityTest (curVal, Confidence)) return curVal;
//
// STEP 2.4
//
biNotPrime:
pMod1 += 2;
if (pMod1 >= primeProd1) pMod1 -= primeProd1;
curVal.Incr2 ();
}
}
protected virtual bool IsPrimeAcceptable (BigInteger bi, object Context)
{
return true;
}
}
}
|