@@ -129,14 +129,24 @@ public static bool IsSsl(TlsContext context)
129
129
return context . ServerVersion . IsSsl ;
130
130
}
131
131
132
+ public static bool IsTlsV11 ( ProtocolVersion version )
133
+ {
134
+ return ProtocolVersion . TLSv11 . IsEqualOrEarlierVersionOf ( version . GetEquivalentTLSVersion ( ) ) ;
135
+ }
136
+
132
137
public static bool IsTlsV11 ( TlsContext context )
133
138
{
134
- return ProtocolVersion . TLSv11 . IsEqualOrEarlierVersionOf ( context . ServerVersion . GetEquivalentTLSVersion ( ) ) ;
139
+ return IsTlsV11 ( context . ServerVersion ) ;
140
+ }
141
+
142
+ public static bool IsTlsV12 ( ProtocolVersion version )
143
+ {
144
+ return ProtocolVersion . TLSv12 . IsEqualOrEarlierVersionOf ( version . GetEquivalentTLSVersion ( ) ) ;
135
145
}
136
146
137
147
public static bool IsTlsV12 ( TlsContext context )
138
148
{
139
- return ProtocolVersion . TLSv12 . IsEqualOrEarlierVersionOf ( context . ServerVersion . GetEquivalentTLSVersion ( ) ) ;
149
+ return IsTlsV12 ( context . ServerVersion ) ;
140
150
}
141
151
142
152
public static void WriteUint8 ( byte i , Stream output )
@@ -712,11 +722,10 @@ public static IList ReadSignatureAlgorithmsExtension(byte[] extensionData)
712
722
public static void EncodeSupportedSignatureAlgorithms ( IList supportedSignatureAlgorithms , bool allowAnonymous ,
713
723
Stream output )
714
724
{
715
- if ( supportedSignatureAlgorithms == null || supportedSignatureAlgorithms . Count < 1
716
- || supportedSignatureAlgorithms . Count >= ( 1 << 15 ) )
717
- {
725
+ if ( supportedSignatureAlgorithms == null )
726
+ throw new ArgumentNullException ( "supportedSignatureAlgorithms" ) ;
727
+ if ( supportedSignatureAlgorithms . Count < 1 || supportedSignatureAlgorithms . Count >= ( 1 << 15 ) )
718
728
throw new ArgumentException ( "must have length from 1 to (2^15 - 1)" , "supportedSignatureAlgorithms" ) ;
719
- }
720
729
721
730
// supported_signature_algorithms
722
731
int length = 2 * supportedSignatureAlgorithms . Count ;
@@ -762,6 +771,27 @@ public static IList ParseSupportedSignatureAlgorithms(bool allowAnonymous, Strea
762
771
return supportedSignatureAlgorithms ;
763
772
}
764
773
774
+ public static void VerifySupportedSignatureAlgorithm ( IList supportedSignatureAlgorithms , SignatureAndHashAlgorithm signatureAlgorithm )
775
+ {
776
+ if ( supportedSignatureAlgorithms == null )
777
+ throw new ArgumentNullException ( "supportedSignatureAlgorithms" ) ;
778
+ if ( supportedSignatureAlgorithms . Count < 1 || supportedSignatureAlgorithms . Count >= ( 1 << 15 ) )
779
+ throw new ArgumentException ( "must have length from 1 to (2^15 - 1)" , "supportedSignatureAlgorithms" ) ;
780
+ if ( signatureAlgorithm == null )
781
+ throw new ArgumentNullException ( "signatureAlgorithm" ) ;
782
+
783
+ if ( signatureAlgorithm . Signature != SignatureAlgorithm . anonymous )
784
+ {
785
+ foreach ( SignatureAndHashAlgorithm entry in supportedSignatureAlgorithms )
786
+ {
787
+ if ( entry . Hash == signatureAlgorithm . Hash && entry . Signature == signatureAlgorithm . Signature )
788
+ return ;
789
+ }
790
+ }
791
+
792
+ throw new TlsFatalAlert ( AlertDescription . illegal_parameter ) ;
793
+ }
794
+
765
795
public static byte [ ] PRF ( TlsContext context , byte [ ] secret , string asciiLabel , byte [ ] seed , int size )
766
796
{
767
797
ProtocolVersion version = context . ServerVersion ;
0 commit comments