Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
339c7d8d
Commit
339c7d8d
authored
Nov 19, 2017
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BC Cert Maker simplified and fixed
parent
64e96e09
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
87 deletions
+7
-87
MainWindow.xaml.cs
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
+1
-1
BCCertificateMaker.cs
Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs
+5
-85
Titanium.Web.Proxy.csproj
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
+1
-1
No files found.
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
View file @
339c7d8d
...
@@ -63,7 +63,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
...
@@ -63,7 +63,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
public
MainWindow
()
public
MainWindow
()
{
{
proxyServer
=
new
ProxyServer
();
proxyServer
=
new
ProxyServer
();
proxyServer
.
CertificateEngine
=
CertificateEngine
.
DefaultWindows
;
//proxyServer.CertificateEngine = CertificateEngine.BouncyCastle
;
proxyServer
.
TrustRootCertificate
=
true
;
proxyServer
.
TrustRootCertificate
=
true
;
proxyServer
.
CertificateManager
.
TrustRootCertificateAsAdministrator
();
proxyServer
.
CertificateManager
.
TrustRootCertificateAsAdministrator
();
proxyServer
.
ForwardToUpstreamGateway
=
true
;
proxyServer
.
ForwardToUpstreamGateway
=
true
;
...
...
Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs
View file @
339c7d8d
...
@@ -88,6 +88,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
...
@@ -88,6 +88,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
var
subjectAlternativeNamesExtension
=
new
DerSequence
(
subjectAlternativeNames
);
var
subjectAlternativeNamesExtension
=
new
DerSequence
(
subjectAlternativeNames
);
certificateGenerator
.
AddExtension
(
X509Extensions
.
SubjectAlternativeName
.
Id
,
false
,
subjectAlternativeNamesExtension
);
certificateGenerator
.
AddExtension
(
X509Extensions
.
SubjectAlternativeName
.
Id
,
false
,
subjectAlternativeNamesExtension
);
}
}
// Subject Public Key
// Subject Public Key
var
keyGenerationParameters
=
new
KeyGenerationParameters
(
secureRandom
,
keyStrength
);
var
keyGenerationParameters
=
new
KeyGenerationParameters
(
secureRandom
,
keyStrength
);
var
keyPairGenerator
=
new
RsaKeyPairGenerator
();
var
keyPairGenerator
=
new
RsaKeyPairGenerator
();
...
@@ -98,6 +99,10 @@ namespace Titanium.Web.Proxy.Network.Certificate
...
@@ -98,6 +99,10 @@ namespace Titanium.Web.Proxy.Network.Certificate
// Set certificate intended purposes to only Server Authentication
// Set certificate intended purposes to only Server Authentication
certificateGenerator
.
AddExtension
(
X509Extensions
.
ExtendedKeyUsage
.
Id
,
false
,
new
ExtendedKeyUsage
(
KeyPurposeID
.
IdKPServerAuth
));
certificateGenerator
.
AddExtension
(
X509Extensions
.
ExtendedKeyUsage
.
Id
,
false
,
new
ExtendedKeyUsage
(
KeyPurposeID
.
IdKPServerAuth
));
if
(
issuerPrivateKey
==
null
)
{
certificateGenerator
.
AddExtension
(
X509Extensions
.
BasicConstraints
.
Id
,
true
,
new
BasicConstraints
(
true
));
}
var
signatureFactory
=
new
Asn1SignatureFactory
(
signatureAlgorithm
,
issuerPrivateKey
??
subjectKeyPair
.
Private
,
secureRandom
);
var
signatureFactory
=
new
Asn1SignatureFactory
(
signatureAlgorithm
,
issuerPrivateKey
??
subjectKeyPair
.
Private
,
secureRandom
);
...
@@ -118,35 +123,14 @@ namespace Titanium.Web.Proxy.Network.Certificate
...
@@ -118,35 +123,14 @@ namespace Titanium.Web.Proxy.Network.Certificate
var
rsaparams
=
new
RsaPrivateCrtKeyParameters
(
rsa
.
Modulus
,
rsa
.
PublicExponent
,
rsa
.
PrivateExponent
,
rsa
.
Prime1
,
rsa
.
Prime2
,
rsa
.
Exponent1
,
var
rsaparams
=
new
RsaPrivateCrtKeyParameters
(
rsa
.
Modulus
,
rsa
.
PublicExponent
,
rsa
.
PrivateExponent
,
rsa
.
Prime1
,
rsa
.
Prime2
,
rsa
.
Exponent1
,
rsa
.
Exponent2
,
rsa
.
Coefficient
);
rsa
.
Exponent2
,
rsa
.
Coefficient
);
#if NET45
// Set private key onto certificate instance
// Set private key onto certificate instance
var
x509Certificate
=
new
X509Certificate2
(
certificate
.
GetEncoded
());
var
x509Certificate
=
new
X509Certificate2
(
certificate
.
GetEncoded
());
x509Certificate
.
PrivateKey
=
DotNetUtilities
.
ToRSA
(
rsaparams
);
x509Certificate
.
PrivateKey
=
DotNetUtilities
.
ToRSA
(
rsaparams
);
x509Certificate
.
FriendlyName
=
subjectName
;
x509Certificate
.
FriendlyName
=
subjectName
;
#else
var
x509Certificate
=
WithPrivateKey
(
certificate
,
rsaparams
);
x509Certificate
.
FriendlyName
=
subjectName
;
#endif
return
x509Certificate
;
return
x509Certificate
;
}
}
private
static
X509Certificate2
WithPrivateKey
(
Org
.
BouncyCastle
.
X509
.
X509Certificate
certificate
,
AsymmetricKeyParameter
privateKey
)
{
const
string
password
=
"password"
;
var
store
=
new
Pkcs12Store
();
var
entry
=
new
X509CertificateEntry
(
certificate
);
store
.
SetCertificateEntry
(
certificate
.
SubjectDN
.
ToString
(),
entry
);
store
.
SetKeyEntry
(
certificate
.
SubjectDN
.
ToString
(),
new
AsymmetricKeyEntry
(
privateKey
),
new
[]
{
entry
});
using
(
var
ms
=
new
MemoryStream
())
{
store
.
Save
(
ms
,
password
.
ToCharArray
(),
new
SecureRandom
(
new
CryptoApiRandomGenerator
()));
return
new
X509Certificate2
(
ms
.
ToArray
(),
password
,
X509KeyStorageFlags
.
Exportable
);
}
}
/// <summary>
/// <summary>
/// Makes the certificate internal.
/// Makes the certificate internal.
/// </summary>
/// </summary>
...
@@ -173,39 +157,11 @@ namespace Titanium.Web.Proxy.Network.Certificate
...
@@ -173,39 +157,11 @@ namespace Titanium.Web.Proxy.Network.Certificate
}
}
else
else
{
{
#if NET45
var
kp
=
DotNetUtilities
.
GetKeyPair
(
signingCertificate
.
PrivateKey
);
var
kp
=
DotNetUtilities
.
GetKeyPair
(
signingCertificate
.
PrivateKey
);
#else
var
rsa
=
signingCertificate
.
GetRSAPrivateKey
();
var
kp
=
GetRsaKeyPair
(
rsa
.
ExportParameters
(
true
));
#endif
return
GenerateCertificate
(
hostName
,
subjectName
,
signingCertificate
.
Subject
,
validFrom
,
validTo
,
issuerPrivateKey
:
kp
.
Private
);
return
GenerateCertificate
(
hostName
,
subjectName
,
signingCertificate
.
Subject
,
validFrom
,
validTo
,
issuerPrivateKey
:
kp
.
Private
);
}
}
}
}
static
AsymmetricCipherKeyPair
GetRsaKeyPair
(
RSAParameters
rp
)
{
BigInteger
modulus
=
new
BigInteger
(
1
,
rp
.
Modulus
);
BigInteger
pubExp
=
new
BigInteger
(
1
,
rp
.
Exponent
);
RsaKeyParameters
pubKey
=
new
RsaKeyParameters
(
false
,
modulus
,
pubExp
);
RsaPrivateCrtKeyParameters
privKey
=
new
RsaPrivateCrtKeyParameters
(
modulus
,
pubExp
,
new
BigInteger
(
1
,
rp
.
D
),
new
BigInteger
(
1
,
rp
.
P
),
new
BigInteger
(
1
,
rp
.
Q
),
new
BigInteger
(
1
,
rp
.
DP
),
new
BigInteger
(
1
,
rp
.
DQ
),
new
BigInteger
(
1
,
rp
.
InverseQ
));
return
new
AsymmetricCipherKeyPair
(
pubKey
,
privKey
);
}
/// <summary>
/// <summary>
/// Makes the certificate internal.
/// Makes the certificate internal.
/// </summary>
/// </summary>
...
@@ -244,41 +200,5 @@ namespace Titanium.Web.Proxy.Network.Certificate
...
@@ -244,41 +200,5 @@ namespace Titanium.Web.Proxy.Network.Certificate
return
MakeCertificateInternal
(
isRoot
,
subject
,
$"CN=
{
subject
}
"
,
DateTime
.
UtcNow
.
AddDays
(-
certificateGraceDays
),
DateTime
.
UtcNow
.
AddDays
(
certificateValidDays
),
isRoot
?
null
:
signingCert
);
return
MakeCertificateInternal
(
isRoot
,
subject
,
$"CN=
{
subject
}
"
,
DateTime
.
UtcNow
.
AddDays
(-
certificateGraceDays
),
DateTime
.
UtcNow
.
AddDays
(
certificateValidDays
),
isRoot
?
null
:
signingCert
);
}
}
class
CryptoApiRandomGenerator
:
IRandomGenerator
{
readonly
RandomNumberGenerator
rndProv
;
public
CryptoApiRandomGenerator
()
{
rndProv
=
RandomNumberGenerator
.
Create
();
}
public
void
AddSeedMaterial
(
byte
[]
seed
)
{
}
public
void
AddSeedMaterial
(
long
seed
)
{
}
public
void
NextBytes
(
byte
[]
bytes
)
{
rndProv
.
GetBytes
(
bytes
);
}
public
void
NextBytes
(
byte
[]
bytes
,
int
start
,
int
len
)
{
if
(
start
<
0
)
throw
new
ArgumentException
(
"Start offset cannot be negative"
,
"start"
);
if
(
bytes
.
Length
<
(
start
+
len
))
throw
new
ArgumentException
(
"Byte array too small for requested offset and length"
);
if
(
bytes
.
Length
==
len
&&
start
==
0
)
{
NextBytes
(
bytes
);
}
else
{
byte
[]
tmpBuf
=
new
byte
[
len
];
NextBytes
(
tmpBuf
);
Array
.
Copy
(
tmpBuf
,
0
,
bytes
,
start
,
len
);
}
}
}
}
}
}
}
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
View file @
339c7d8d
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.1.
2
" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.1.
3
" />
<PackageReference Include="StreamExtended" Version="1.0.81" />
<PackageReference Include="StreamExtended" Version="1.0.81" />
</ItemGroup>
</ItemGroup>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment