2
0

Fix issue with passing context in Java algorithm and test case.

This commit is contained in:
Maarten Billemont 2014-12-12 10:54:28 -05:00
parent 19202e07d4
commit 0fdf894bf0
4 changed files with 9 additions and 6 deletions

View File

@ -112,6 +112,8 @@ public class MasterKey {
siteContext == null? "(null)": siteContext ); siteContext == null? "(null)": siteContext );
byte[] sitePasswordInfo = Bytes.concat( siteScope.getBytes( MP_charset ), siteNameLengthBytes, siteNameBytes, siteCounterBytes ); byte[] sitePasswordInfo = Bytes.concat( siteScope.getBytes( MP_charset ), siteNameLengthBytes, siteNameBytes, siteCounterBytes );
if (siteContextBytes != null)
sitePasswordInfo = Bytes.concat( sitePasswordInfo, siteContextLengthBytes, siteContextBytes );
logger.trc( "sitePasswordInfo ID: %s", CodeUtils.encodeHex( idForBytes( sitePasswordInfo ) ) ); logger.trc( "sitePasswordInfo ID: %s", CodeUtils.encodeHex( idForBytes( sitePasswordInfo ) ) );
byte[] sitePasswordSeed = MP_mac.of( masterKey, sitePasswordInfo ); byte[] sitePasswordSeed = MP_mac.of( masterKey, sitePasswordInfo );

View File

@ -4,6 +4,7 @@ import static com.lyndir.lhunath.opal.system.util.ObjectUtils.*;
import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.lhunath.opal.system.logging.Logger;
import com.lyndir.lhunath.opal.system.util.NNSupplier; import com.lyndir.lhunath.opal.system.util.NNSupplier;
import com.lyndir.lhunath.opal.system.util.NSupplier;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -117,7 +118,7 @@ public class MPWTests {
return parentCase.getSiteVariant().name(); return parentCase.getSiteVariant().name();
} }
} ); } );
siteContext = ifNotNullElse( siteContext, new NNSupplier<String>() { siteContext = ifNotNullElseNullable( siteContext, new NSupplier<String>() {
@Nonnull @Nonnull
@Override @Override
public String get() { public String get() {

View File

@ -3,6 +3,7 @@ package com.lyndir.masterpassword;
import static org.testng.Assert.*; import static org.testng.Assert.*;
import com.google.common.io.Resources; import com.google.common.io.Resources;
import com.lyndir.lhunath.opal.system.CodeUtils;
import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.lhunath.opal.system.logging.Logger;
import java.net.URL; import java.net.URL;
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
@ -35,9 +36,9 @@ public class MasterKeyTest {
for (MPWTests.Case testCase : tests.getCases()) { for (MPWTests.Case testCase : tests.getCases()) {
MasterKey masterKey = new MasterKey( testCase.getFullName(), testCase.getMasterPassword() ); MasterKey masterKey = new MasterKey( testCase.getFullName(), testCase.getMasterPassword() );
assertEquals( masterKey.encode( testCase.getSiteName(), testCase.getSiteType(), testCase.getSiteCounter(), assertEquals(
testCase.getSiteVariant(), testCase.getSiteContext() ), testCase.getResult(), masterKey.encode( testCase.getSiteName(), testCase.getSiteType(), testCase.getSiteCounter(), testCase.getSiteVariant(),
"Failed test case: " + testCase ); testCase.getSiteContext() ), testCase.getResult(), "Failed test case: " + testCase );
} }
} }
@ -55,7 +56,7 @@ public class MasterKeyTest {
for (MPWTests.Case testCase : tests.getCases()) { for (MPWTests.Case testCase : tests.getCases()) {
MasterKey masterKey = new MasterKey( testCase.getFullName(), testCase.getMasterPassword() ); MasterKey masterKey = new MasterKey( testCase.getFullName(), testCase.getMasterPassword() );
assertEquals( masterKey.getKeyID(), testCase.getKeyID(), "Failed test case: " + testCase ); assertEquals( CodeUtils.encodeHex( masterKey.getKeyID() ), testCase.getKeyID(), "Failed test case: " + testCase );
} }
} }

View File

@ -7,7 +7,6 @@
<siteCounter>1</siteCounter> <siteCounter>1</siteCounter>
<siteType>GeneratedLong</siteType> <siteType>GeneratedLong</siteType>
<siteVariant>Password</siteVariant> <siteVariant>Password</siteVariant>
<siteContext />
<result>Jejr5[RepuSosp</result> <result>Jejr5[RepuSosp</result>
</case> </case>
<case id="mb_fullName" parent="default"> <case id="mb_fullName" parent="default">