Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
NEXUS-4194: all fine and dandy with SHA1, but I completely forgot abo…
Browse files Browse the repository at this point in the history
…ut MD5 (and UTs does catch those just fine)

git-svn-id: file:///opt/svn/repositories/sonatype.org/nexus/trunk/nexus@7979 2aa8b3fc-8ebb-4439-a84f-95066eaea8ab
  • Loading branch information
cstamas committed Apr 2, 2011
1 parent dc32530 commit 1077bfd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
Expand Up @@ -54,6 +54,10 @@ public class RequestContext
/** The digest sha1 key. */
public static final String CTX_DIGEST_SHA1_KEY = "digest.sha1";

/** The digest md5 key. @deprecated MD5 is deprecated, use SHA1. */
@Deprecated
public static final String CTX_DIGEST_MD5_KEY = "digest.md5";

/**
* Context key to mark request as used for auth check only, so repo impl will know there is no work required (i.e.
* interpolation, etc.)
Expand Down
Expand Up @@ -46,7 +46,7 @@ public class DigestCalculatingInspector

/** The digest md5 key. */
@Deprecated
public static String DIGEST_MD5_KEY = "digest.md5";
public static String DIGEST_MD5_KEY = RequestContext.CTX_DIGEST_MD5_KEY;

/** The digest sha1 key. */
public static String DIGEST_SHA1_KEY = RequestContext.CTX_DIGEST_SHA1_KEY;
Expand All @@ -68,6 +68,10 @@ public boolean isHandled( StorageItem item )
item.getAttributes().put( DIGEST_SHA1_KEY,
String.valueOf( item.getItemContext().get( RequestContext.CTX_DIGEST_SHA1_KEY ) ) );

// do this one "blindly"
item.getAttributes().put( DIGEST_MD5_KEY,
String.valueOf( item.getItemContext().get( RequestContext.CTX_DIGEST_MD5_KEY ) ) );

// we did our job, we "lifted" the digest from context
return false;
}
Expand Down
Expand Up @@ -190,27 +190,24 @@ public Iterator<StorageItem> iterateItems( Repository repository, ResourceStoreI
protected void prepareStorageFileItemForStore( final StorageFileItem item )
throws LocalStorageException
{
// repack digest keys if needed (from attributes to context), if this items comes from another repo it will
// have them
if ( item.getAttributes().containsKey( RequestContext.CTX_DIGEST_SHA1_KEY ) )
{
item.getItemContext().put( RequestContext.CTX_DIGEST_SHA1_KEY,
item.getAttributes().get( RequestContext.CTX_DIGEST_SHA1_KEY ) );
}

try
{
// replace content locator
ChecksummingContentLocator ccl =
ChecksummingContentLocator sha1cl =
new ChecksummingContentLocator( item.getContentLocator(), MessageDigest.getInstance( "SHA1" ),
RequestContext.CTX_DIGEST_SHA1_KEY, item.getItemContext() );

item.setContentLocator( ccl );
// md5 is deprecated but still calculated
ChecksummingContentLocator md5cl =
new ChecksummingContentLocator( sha1cl, MessageDigest.getInstance( "MD5" ),
RequestContext.CTX_DIGEST_MD5_KEY, item.getItemContext() );

item.setContentLocator( md5cl );
}
catch ( NoSuchAlgorithmException e )
{
throw new LocalStorageException(
"The JVM does not support SHA1 MessageDigest, that is essential for Nexus. We cannot write to local storage! Please run Nexus on JVM that does provide this.",
"The JVM does not support SHA1 MessageDigest or MD5 MessageDigest, that is essential for Nexus. We cannot write to local storage! Please run Nexus on JVM that does provide these MessageDigests.",
e );
}
}
Expand Down

0 comments on commit 1077bfd

Please sign in to comment.