Skip to content

Commit c78829a

Browse files
authored
Merge pull request #44 from CryptoPro/gost_xml_encrypt
Gost xml encrypt
2 parents 3341718 + fbd3f85 commit c78829a

91 files changed

Lines changed: 10808 additions & 843 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

appveyor.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ for:
7676
- cmd: '"C:\Program Files\Crypto Pro\CSP\csptest" -enum -info -type PP_ENUMALGS'
7777
# getting patched nuget packages with gost support
7878
- cmd: git clone https://github.com/CryptoProLLC/NetStandard.Library
79+
- cmd: cd NetStandard.Library
80+
- cmd: git checkout %APPVEYOR_REPO_BRANCH%
81+
- cmd: cd ..
7982
- ps: New-Item -ItemType Directory -Force -Path "$env:userprofile\.nuget\packages\netstandard.library"
8083
- ps: Copy-Item -Force -Recurse ".\NetStandard.Library\nugetReady\netstandard.library" -Destination "$env:userprofile\.nuget\packages\"
8184
# enable-rdp
@@ -104,7 +107,11 @@ for:
104107
- .\\.dotnet\\dotnet msbuild src\\System.Security.Cryptography.Csp\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Encryption.Gost3410.Tests.Gost3410_2012_256CryptoServiceProviderTests" /p:ForceRunTests=true
105108
- .\\.dotnet\\dotnet msbuild src\\System.Security.Cryptography.Csp\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Encryption.Gost3410.Tests.Gost3410_2012_512CryptoServiceProviderTests" /p:ForceRunTests=true
106109
- .\\.dotnet\\dotnet msbuild src\\System.Security.Cryptography.Csp\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Csp.Tests.Gost28147CryptoServiceProviderTest" /p:ForceRunTests=true
110+
- .\\.dotnet\\dotnet msbuild src\\System.Security.Cryptography.Csp\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Encryption.KeyExchange.Tests.GostKeyWrapTest" /p:ForceRunTests=true
111+
- .\\.dotnet\\dotnet msbuild src\\System.Security.Cryptography.Csp\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Encryption.KeyExchange.Tests.GostKeyExchange" /p:ForceRunTests=true
112+
- .\\.dotnet\\dotnet msbuild src\\System.Security.Cryptography.Csp\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Encryption.KeyExchange.Tests.GostSharedSecretTest" /p:ForceRunTests=true
107113
- .\\.dotnet\\dotnet msbuild src\\System.Security.Cryptography.Xml\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Xml.Tests.GostSignedXmlTest" /p:ForceRunTests=true
114+
- .\\.dotnet\\dotnet msbuild src\\System.Security.Cryptography.Xml\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Xml.Tests.GostEncryptedXmlTest" /p:ForceRunTests=true
108115
- .\\.dotnet\\dotnet msbuild src\\System.Security.Cryptography.X509Certificates\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.X509Certificates.Tests.GostPfxTests" /p:ForceRunTests=true
109116
- .\\.dotnet\\dotnet msbuild src\\System.Security.Cryptography.Pkcs\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Pkcs.Tests.GostNonPersistCmsTests" /p:ForceRunTests=true
110117

@@ -145,6 +152,9 @@ for:
145152
- sh: /opt/cprocsp/bin/amd64/csptest -keyset -enum_c -verifyc -fqcn
146153
# getting patched nuget packages with gost support
147154
- sh: git clone https://github.com/CryptoProLLC/NetStandard.Library
155+
- sh: cd NetStandard.Library
156+
- sh: git checkout $APPVEYOR_REPO_BRANCH
157+
- sh: cd ..
148158
- sh: mkdir -p ~/.nuget/packages/netstandard.library
149159
- sh: cp -r ./NetStandard.Library/nugetReady/netstandard.library ~/.nuget/packages/
150160
# disable warnings
@@ -172,7 +182,11 @@ for:
172182
- ./.dotnet/dotnet msbuild src\\System.Security.Cryptography.Csp\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Encryption.Gost3410.Tests.Gost3410_2012_256CryptoServiceProviderTests" /p:ForceRunTests=true
173183
- ./.dotnet/dotnet msbuild src\\System.Security.Cryptography.Csp\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Encryption.Gost3410.Tests.Gost3410_2012_512CryptoServiceProviderTests" /p:ForceRunTests=true
174184
- ./.dotnet/dotnet msbuild src\\System.Security.Cryptography.Csp\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Csp.Tests.Gost28147CryptoServiceProviderTest" /p:ForceRunTests=true
185+
- ./.dotnet/dotnet msbuild src\\System.Security.Cryptography.Csp\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Encryption.KeyExchange.Tests.GostKeyWrapTest" /p:ForceRunTests=true
186+
- ./.dotnet/dotnet msbuild src\\System.Security.Cryptography.Csp\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Encryption.KeyExchange.Tests.GostKeyExchange" /p:ForceRunTests=true
187+
- ./.dotnet/dotnet msbuild src\\System.Security.Cryptography.Csp\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Encryption.KeyExchange.Tests.GostSharedSecretTest" /p:ForceRunTests=true
175188
- ./.dotnet/dotnet msbuild src\\System.Security.Cryptography.Xml\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Xml.Tests.GostSignedXmlTest" /p:ForceRunTests=true
189+
- ./.dotnet/dotnet msbuild src\\System.Security.Cryptography.Xml\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Xml.Tests.GostEncryptedXmlTest" /p:ForceRunTests=true
176190
- ./.dotnet/dotnet msbuild src\\System.Security.Cryptography.X509Certificates\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.X509Certificates.Tests.GostPfxTests" /p:ForceRunTests=true
177191
- ./.dotnet/dotnet msbuild src\\System.Security.Cryptography.Pkcs\\tests /t:BuildAndTest "/p:XunitOptions=-class System.Security.Cryptography.Pkcs.Tests.GostNonPersistCmsTests" /p:ForceRunTests=true
178192
artifacts:

cspTools/test_certs/README

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Нигде в явном виде файлы не используются, но используются их копии в виде массива байт в тестах.
2+
3+
Пусть будут тут.
1.15 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
namespace System.Security.Cryptography
2+
{
3+
class Gost28147_89_BlobParameters : Asn1Type
4+
{
5+
public Gost28147_89_ParamSet encryptionParamSet;
6+
public Asn1OpenExt extElem1;
7+
8+
public Gost28147_89_BlobParameters() : base()
9+
{
10+
}
11+
12+
/// <summary>
13+
/// This constructor sets all elements to references to the
14+
/// given objects
15+
/// </summary>
16+
public Gost28147_89_BlobParameters(
17+
Gost28147_89_ParamSet encryptionParamSet_
18+
)
19+
: base()
20+
{
21+
encryptionParamSet = encryptionParamSet_;
22+
}
23+
24+
/// <summary>
25+
/// This constructor allows primitive data to be passed for all
26+
/// primitive elements. It will create new object wrappers for
27+
/// the primitive data and set other elements to references to
28+
/// the given objects
29+
/// </summary>
30+
public Gost28147_89_BlobParameters(int[] encryptionParamSet_
31+
)
32+
: base()
33+
{
34+
encryptionParamSet = new Gost28147_89_ParamSet(encryptionParamSet_);
35+
}
36+
37+
public void Init()
38+
{
39+
encryptionParamSet = null;
40+
extElem1 = null;
41+
}
42+
43+
public override void Decode
44+
(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
45+
{
46+
int llen = (explicitTagging) ?
47+
MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;
48+
49+
Init();
50+
51+
// decode SEQUENCE
52+
53+
Asn1BerDecodeContext context =
54+
new Asn1BerDecodeContext(buffer, llen);
55+
56+
IntHolder elemLen = new IntHolder();
57+
58+
// decode encryptionParamSet
59+
60+
if (context.MatchElemTag(Asn1Tag.Universal, Asn1Tag.PRIM, 6, elemLen, false))
61+
{
62+
encryptionParamSet = new Gost28147_89_ParamSet();
63+
encryptionParamSet.Decode(buffer, true, elemLen.Value);
64+
}
65+
else
66+
throw new Exception("Asn1MissingRequiredException");
67+
68+
// decode extElem1
69+
70+
if (!context.Expired())
71+
{
72+
Asn1Tag _tag = buffer.PeekTag();
73+
if (_tag.Equals(Asn1Tag.Universal, Asn1Tag.PRIM, 6))
74+
{
75+
throw new Exception("Asn1SeqOrderException");
76+
}
77+
else
78+
{
79+
extElem1 = new Asn1OpenExt();
80+
while (!context.Expired())
81+
{
82+
extElem1.DecodeComponent(buffer);
83+
}
84+
}
85+
}
86+
else
87+
extElem1 = null;
88+
89+
}
90+
91+
public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
92+
{
93+
int _aal = 0, len;
94+
95+
// encode extElem1
96+
97+
if (extElem1 != null)
98+
{
99+
len = extElem1.Encode(buffer, false);
100+
_aal += len;
101+
}
102+
103+
// encode encryptionParamSet
104+
105+
len = encryptionParamSet.Encode(buffer, true);
106+
_aal += len;
107+
108+
if (explicitTagging)
109+
{
110+
_aal += buffer.EncodeTagAndLength(Asn1Tag.Sequence, _aal);
111+
}
112+
113+
return (_aal);
114+
}
115+
116+
}
117+
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
namespace System.Security.Cryptography
2+
{
3+
4+
class Gost28147_89_EncryptedKey : Asn1Type
5+
{
6+
public Gost28147_89_Key encryptedKey;
7+
public Gost28147_89_Key maskKey; // optional
8+
public Gost28147_89_MAC macKey;
9+
10+
public Gost28147_89_EncryptedKey() : base()
11+
{
12+
}
13+
14+
/// <summary>
15+
/// This constructor sets all elements to references to the
16+
/// given objects
17+
/// </summary>
18+
public Gost28147_89_EncryptedKey(
19+
Gost28147_89_Key encryptedKey_,
20+
Gost28147_89_Key maskKey_,
21+
Gost28147_89_MAC macKey_
22+
)
23+
: base()
24+
{
25+
encryptedKey = encryptedKey_;
26+
maskKey = maskKey_;
27+
macKey = macKey_;
28+
}
29+
30+
/// <summary>
31+
/// This constructor is for required elements only. It sets
32+
/// all elements to references to the given objects
33+
/// </summary>
34+
public Gost28147_89_EncryptedKey(
35+
Gost28147_89_Key encryptedKey_,
36+
Gost28147_89_MAC macKey_
37+
)
38+
: base()
39+
{
40+
encryptedKey = encryptedKey_;
41+
macKey = macKey_;
42+
}
43+
44+
/// <summary>
45+
/// This constructor allows primitive data to be passed for all
46+
/// primitive elements. It will create new object wrappers for
47+
/// the primitive data and set other elements to references to
48+
/// the given objects
49+
/// </summary>
50+
public Gost28147_89_EncryptedKey(byte[] encryptedKey_,
51+
byte[] maskKey_,
52+
byte[] macKey_
53+
)
54+
: base()
55+
{
56+
encryptedKey = new Gost28147_89_Key(encryptedKey_);
57+
maskKey = new Gost28147_89_Key(maskKey_);
58+
macKey = new Gost28147_89_MAC(macKey_);
59+
}
60+
61+
/// <summary>
62+
/// This constructor is for required elements only. It allows
63+
/// primitive data to be passed for all primitive elements.
64+
/// It will create new object wrappers for the primitive data
65+
/// and set other elements to references to the given objects.
66+
/// </summary>
67+
public Gost28147_89_EncryptedKey(
68+
byte[] encryptedKey_,
69+
byte[] macKey_
70+
)
71+
: base()
72+
{
73+
encryptedKey = new Gost28147_89_Key(encryptedKey_);
74+
macKey = new Gost28147_89_MAC(macKey_);
75+
}
76+
77+
public void Init()
78+
{
79+
encryptedKey = null;
80+
maskKey = null;
81+
macKey = null;
82+
}
83+
84+
public override void Decode
85+
(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
86+
{
87+
int llen = (explicitTagging) ?
88+
MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;
89+
90+
Init();
91+
92+
// decode SEQUENCE
93+
94+
Asn1BerDecodeContext context =
95+
new Asn1BerDecodeContext(buffer, llen);
96+
97+
IntHolder elemLen = new IntHolder();
98+
99+
// decode encryptedKey
100+
101+
if (context.MatchElemTag(Asn1Tag.Universal, Asn1Tag.PRIM, 4, elemLen, false))
102+
{
103+
encryptedKey = new Gost28147_89_Key();
104+
encryptedKey.Decode(buffer, true, elemLen.Value);
105+
}
106+
else
107+
throw new Exception("Asn1MissingRequiredException");
108+
109+
// decode maskKey
110+
111+
if (context.MatchElemTag(Asn1Tag.CTXT, Asn1Tag.PRIM, 0, elemLen, true))
112+
{
113+
maskKey = new Gost28147_89_Key();
114+
maskKey.Decode(buffer, false, elemLen.Value);
115+
}
116+
117+
// decode macKey
118+
119+
if (context.MatchElemTag(Asn1Tag.Universal, Asn1Tag.PRIM, 4, elemLen, false))
120+
{
121+
macKey = new Gost28147_89_MAC();
122+
macKey.Decode(buffer, true, elemLen.Value);
123+
if (!(macKey.Length == 4))
124+
{
125+
throw new Exception("Asn1ConsVioException");
126+
}
127+
128+
}
129+
else
130+
throw new Exception("Asn1MissingRequiredException");
131+
132+
}
133+
134+
public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
135+
{
136+
int _aal = 0, len;
137+
138+
// encode macKey
139+
140+
if (!(macKey.Length == 4))
141+
{
142+
throw new Exception("Asn1ConsVioException");
143+
}
144+
145+
len = macKey.Encode(buffer, true);
146+
_aal += len;
147+
148+
// encode maskKey
149+
150+
if (maskKey != null)
151+
{
152+
len = maskKey.Encode(buffer, false);
153+
_aal += len;
154+
_aal += buffer.EncodeTagAndLength(Asn1Tag.CTXT, Asn1Tag.PRIM, 0, len);
155+
}
156+
157+
// encode encryptedKey
158+
159+
len = encryptedKey.Encode(buffer, true);
160+
_aal += len;
161+
162+
if (explicitTagging)
163+
{
164+
_aal += buffer.EncodeTagAndLength(Asn1Tag.Sequence, _aal);
165+
}
166+
167+
return (_aal);
168+
}
169+
170+
}
171+
}

0 commit comments

Comments
 (0)