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
448e450a
Commit
448e450a
authored
Jan 04, 2019
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#521 Fix modroid start issue
parent
4220af29
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
23 deletions
+39
-23
DefaultCertificateDiskCache.cs
...Titanium.Web.Proxy/Network/DefaultCertificateDiskCache.cs
+37
-21
ICertificateCache.cs
src/Titanium.Web.Proxy/Network/ICertificateCache.cs
+2
-2
No files found.
src/Titanium.Web.Proxy/Network/DefaultCertificateDiskCache.cs
View file @
448e450a
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
using
System.IO
;
using
System.IO
;
using
System.Reflection
;
using
System.Reflection
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Security.Cryptography.X509Certificates
;
using
Titanium.Web.Proxy.Helpers
;
namespace
Titanium.Web.Proxy.Network
namespace
Titanium.Web.Proxy.Network
{
{
...
@@ -13,24 +14,24 @@ namespace Titanium.Web.Proxy.Network
...
@@ -13,24 +14,24 @@ namespace Titanium.Web.Proxy.Network
private
string
rootCertificatePath
;
private
string
rootCertificatePath
;
private
string
certificatePath
;
private
string
certificatePath
;
public
X509Certificate2
LoadRootCertificate
(
string
n
ame
,
string
password
,
X509KeyStorageFlags
storageFlags
)
public
X509Certificate2
LoadRootCertificate
(
string
pathOrN
ame
,
string
password
,
X509KeyStorageFlags
storageFlags
)
{
{
string
filePath
=
getRootCertificatePath
(
n
ame
);
string
path
=
getRootCertificatePath
(
pathOrN
ame
);
return
loadCertificate
(
fileP
ath
,
password
,
storageFlags
);
return
loadCertificate
(
p
ath
,
password
,
storageFlags
);
}
}
public
void
SaveRootCertificate
(
string
n
ame
,
string
password
,
X509Certificate2
certificate
)
public
void
SaveRootCertificate
(
string
pathOrN
ame
,
string
password
,
X509Certificate2
certificate
)
{
{
string
filePath
=
getRootCertificatePath
(
n
ame
);
string
path
=
getRootCertificatePath
(
pathOrN
ame
);
byte
[]
exported
=
certificate
.
Export
(
X509ContentType
.
Pkcs12
,
password
);
byte
[]
exported
=
certificate
.
Export
(
X509ContentType
.
Pkcs12
,
password
);
File
.
WriteAllBytes
(
fileP
ath
,
exported
);
File
.
WriteAllBytes
(
p
ath
,
exported
);
}
}
/// <inheritdoc />
/// <inheritdoc />
public
X509Certificate2
LoadCertificate
(
string
subjectName
,
X509KeyStorageFlags
storageFlags
)
public
X509Certificate2
LoadCertificate
(
string
subjectName
,
X509KeyStorageFlags
storageFlags
)
{
{
string
fileP
ath
=
Path
.
Combine
(
getCertificatePath
(),
subjectName
+
defaultCertificateFileExtension
);
string
p
ath
=
Path
.
Combine
(
getCertificatePath
(),
subjectName
+
defaultCertificateFileExtension
);
return
loadCertificate
(
fileP
ath
,
string
.
Empty
,
storageFlags
);
return
loadCertificate
(
p
ath
,
string
.
Empty
,
storageFlags
);
}
}
/// <inheritdoc />
/// <inheritdoc />
...
@@ -55,12 +56,12 @@ namespace Titanium.Web.Proxy.Network
...
@@ -55,12 +56,12 @@ namespace Titanium.Web.Proxy.Network
certificatePath
=
null
;
certificatePath
=
null
;
}
}
private
X509Certificate2
loadCertificate
(
string
fileP
ath
,
string
password
,
X509KeyStorageFlags
storageFlags
)
private
X509Certificate2
loadCertificate
(
string
p
ath
,
string
password
,
X509KeyStorageFlags
storageFlags
)
{
{
byte
[]
exported
;
byte
[]
exported
;
try
try
{
{
exported
=
File
.
ReadAllBytes
(
fileP
ath
);
exported
=
File
.
ReadAllBytes
(
p
ath
);
}
}
catch
(
IOException
)
catch
(
IOException
)
{
{
...
@@ -71,15 +72,15 @@ namespace Titanium.Web.Proxy.Network
...
@@ -71,15 +72,15 @@ namespace Titanium.Web.Proxy.Network
return
new
X509Certificate2
(
exported
,
password
,
storageFlags
);
return
new
X509Certificate2
(
exported
,
password
,
storageFlags
);
}
}
private
string
getRootCertificatePath
(
string
filePath
)
private
string
getRootCertificatePath
(
string
pathOrName
)
{
{
if
(
Path
.
IsPathRooted
(
filePath
))
if
(
Path
.
IsPathRooted
(
pathOrName
))
{
{
return
filePath
;
return
pathOrName
;
}
}
return
Path
.
Combine
(
getRootCertificateDirectory
(),
return
Path
.
Combine
(
getRootCertificateDirectory
(),
string
.
IsNullOrEmpty
(
filePath
)
?
defaultRootCertificateFileName
:
filePath
);
string
.
IsNullOrEmpty
(
pathOrName
)
?
defaultRootCertificateFileName
:
pathOrName
);
}
}
private
string
getCertificatePath
()
private
string
getCertificatePath
()
...
@@ -104,17 +105,32 @@ namespace Titanium.Web.Proxy.Network
...
@@ -104,17 +105,32 @@ namespace Titanium.Web.Proxy.Network
{
{
if
(
rootCertificatePath
==
null
)
if
(
rootCertificatePath
==
null
)
{
{
string
assemblyLocation
=
GetType
().
Assembly
.
Location
;
if
(
RunTime
.
IsUwpOnWindows
)
{
// dynamically loaded assemblies returns string.Empty location
rootCertificatePath
=
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
LocalApplicationData
);
if
(
assemblyLocation
==
string
.
Empty
)
}
else
if
(
RunTime
.
IsLinux
)
{
{
assemblyLocation
=
Assembly
.
GetEntryAssembly
().
Location
;
rootCertificatePath
=
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
ApplicationData
)
;
}
}
else
if
(
RunTime
.
IsMac
)
{
rootCertificatePath
=
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
ApplicationData
);
}
else
{
string
assemblyLocation
=
GetType
().
Assembly
.
Location
;
string
path
=
Path
.
GetDirectoryName
(
assemblyLocation
);
// dynamically loaded assemblies returns string.Empty location
if
(
assemblyLocation
==
string
.
Empty
)
{
assemblyLocation
=
Assembly
.
GetEntryAssembly
().
Location
;
}
rootCertificatePath
=
path
??
throw
new
NullReferenceException
();
string
path
=
Path
.
GetDirectoryName
(
assemblyLocation
);
rootCertificatePath
=
path
??
throw
new
NullReferenceException
();
}
}
}
return
rootCertificatePath
;
return
rootCertificatePath
;
...
...
src/Titanium.Web.Proxy/Network/ICertificateCache.cs
View file @
448e450a
...
@@ -7,12 +7,12 @@ namespace Titanium.Web.Proxy.Network
...
@@ -7,12 +7,12 @@ namespace Titanium.Web.Proxy.Network
/// <summary>
/// <summary>
/// Loads the root certificate from the storage.
/// Loads the root certificate from the storage.
/// </summary>
/// </summary>
X509Certificate2
LoadRootCertificate
(
string
n
ame
,
string
password
,
X509KeyStorageFlags
storageFlags
);
X509Certificate2
LoadRootCertificate
(
string
pathOrN
ame
,
string
password
,
X509KeyStorageFlags
storageFlags
);
/// <summary>
/// <summary>
/// Saves the root certificate to the storage.
/// Saves the root certificate to the storage.
/// </summary>
/// </summary>
void
SaveRootCertificate
(
string
n
ame
,
string
password
,
X509Certificate2
certificate
);
void
SaveRootCertificate
(
string
pathOrN
ame
,
string
password
,
X509Certificate2
certificate
);
/// <summary>
/// <summary>
/// Loads certificate from the storage. Returns true if certificate does not exist.
/// Loads certificate from the storage. Returns true if certificate does not exist.
...
...
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