@@ -13,14 +13,18 @@ class Keepass2TotpPluginAdapter : ITotpPluginAdapter
1313 public TotpData GetTotpData ( IDictionary < string , string > entryFields , Context ctx , bool muteWarnings )
1414 {
1515 TotpData res = new TotpData ( ) ;
16- byte [ ] pbSecret = ( GetOtpSecret ( entryFields , "TimeOtp-" ) ?? MemUtil . EmptyByteArray ) ;
16+ byte [ ] pbSecret = ( GetOtpSecret ( entryFields , "TimeOtp-" , out string secretFieldKey ) ?? MemUtil . EmptyByteArray ) ;
17+
1718 if ( pbSecret . Length == 0 )
1819 return res ;
1920
21+ res . InternalFields . Add ( secretFieldKey ) ;
22+
2023 string strPeriod ;
2124 uint uPeriod = 0 ;
2225 if ( entryFields . TryGetValue ( "TimeOtp-Period" , out strPeriod ) )
2326 {
27+ res . InternalFields . Add ( "TimeOtp-Period" ) ;
2428 uint . TryParse ( strPeriod , out uPeriod ) ;
2529 }
2630
@@ -33,6 +37,7 @@ public TotpData GetTotpData(IDictionary<string, string> entryFields, Context ctx
3337 uint uLength = 0 ;
3438 if ( entryFields . TryGetValue ( "TimeOtp-Length" , out strLength ) )
3539 {
40+ res . InternalFields . Add ( "TimeOtp-Length" ) ;
3641 uint . TryParse ( strLength , out uLength ) ;
3742 }
3843
@@ -41,6 +46,8 @@ public TotpData GetTotpData(IDictionary<string, string> entryFields, Context ctx
4146
4247 string strAlg ;
4348 entryFields . TryGetValue ( "TimeOtp-Algorithm" , out strAlg ) ;
49+ if ( ! string . IsNullOrEmpty ( strAlg ) )
50+ res . InternalFields . Add ( "TimeOtp-Algorithm" ) ;
4451
4552 res . HashAlgorithm = strAlg ;
4653 res . TotpSecret = pbSecret ;
@@ -51,32 +58,37 @@ public TotpData GetTotpData(IDictionary<string, string> entryFields, Context ctx
5158 }
5259
5360
54- private static byte [ ] GetOtpSecret ( IDictionary < string , string > entryFields , string strPrefix )
61+ private static byte [ ] GetOtpSecret ( IDictionary < string , string > entryFields , string strPrefix , out string secretFieldKey )
5562 {
5663 try
5764 {
5865 string str ;
59- entryFields . TryGetValue ( strPrefix + "Secret" , out str ) ;
60- if ( ! string . IsNullOrEmpty ( str ) )
66+ secretFieldKey = strPrefix + "Secret" ;
67+ entryFields . TryGetValue ( secretFieldKey , out str ) ;
68+ if ( ! string . IsNullOrEmpty ( str ) )
6169 return StrUtil . Utf8 . GetBytes ( str ) ;
62-
63- entryFields . TryGetValue ( strPrefix + "Secret-Hex" , out str ) ;
70+
71+ secretFieldKey = strPrefix + "Secret-Hex" ;
72+ entryFields . TryGetValue ( secretFieldKey , out str ) ;
6473 if ( ! string . IsNullOrEmpty ( str ) )
6574 return MemUtil . HexStringToByteArray ( str ) ;
66-
67- entryFields . TryGetValue ( strPrefix + "Secret-Base32" , out str ) ;
75+
76+ secretFieldKey = strPrefix + "Secret-Base32" ;
77+ entryFields . TryGetValue ( secretFieldKey , out str ) ;
6878 if ( ! string . IsNullOrEmpty ( str ) )
6979 return MemUtil . ParseBase32 ( str ) ;
7080
71- entryFields . TryGetValue ( strPrefix + "Secret-Base64" , out str ) ;
81+ secretFieldKey = strPrefix + "Secret-Base64" ;
82+ entryFields . TryGetValue ( secretFieldKey , out str ) ;
7283 if ( ! string . IsNullOrEmpty ( str ) )
7384 return Convert . FromBase64String ( str ) ;
85+
7486 }
7587 catch ( Exception e )
7688 {
7789 Kp2aLog . LogUnexpectedError ( e ) ;
7890 }
79-
91+ secretFieldKey = null ;
8092 return null ;
8193 }
8294 }
0 commit comments