Projects >> eucalyptus >>830fcd6aa7a2e7eda27bc063de383268190bfea6

Chunk
Conflicting content
				certString= httpRequest.getAndRemoveHeader(StorageProperties.StorageParameters.EucaCert.toString());
			}
			String data = verb + "\n" + date + "\n" + addr + "\n";
<<<<<<< HEAD

			Signature sig;
			boolean valid = false;
			try {
				try {
					PublicKey publicKey = SystemCredentialProvider.getCredentialProvider(Component.storage).getCertificate().getPublicKey();
					sig = Signature.getInstance("SHA1withRSA");
					sig.initVerify(publicKey);
					sig.update(data.getBytes());
					valid = sig.verify(Base64.decode(signature));
				} catch ( Exception e ) {
					LOG.warn ("Authentication: certificate not found in keystore");
				} finally {
					if( !valid && certString != null ) {
						try {
							X509Certificate nodeCert = Hashes.getPemCert( Base64.decode( certString ) );
							PublicKey publicKey = nodeCert.getPublicKey( );
							sig = Signature.getInstance( "SHA1withRSA" );
							sig.initVerify( publicKey );
							sig.update( data.getBytes( ) );
							valid = sig.verify( Base64.decode( signature ) );
						} catch ( Exception e2 ) {
							LOG.warn ("Authentication exception: " + e2.getMessage());
						}            
					}
				}
			} catch (Exception ex) {
				LOG.warn ("Authentication exception: " + ex.getMessage());
				ex.printStackTrace();
			}

			if(!valid) {
				throw new AuthenticationException( "User authentication failed." );
			}
			String effectiveUserID = httpRequest.getAndRemoveHeader(SecurityParameter.AWSAccessKeyId.toString());
=======
			String effectiveUserID = httpRequest.getAndRemoveHeader(StorageProperties.StorageParameters.EucaEffectiveUserId.toString());
>>>>>>> 6178d2cdaf08f808b0652d21fac14474604f4d1b
			try {
				SecurityContext.getLoginContext(new WalrusWrappedComponentCredentials(httpRequest.getCorrelationId(), data, effectiveUserID, signature, certString)).login();
			} catch(Exception ex) {
Solution content
				certString= httpRequest.getAndRemoveHeader(StorageProperties.StorageParameters.EucaCert.toString());
			}
			String data = verb + "\n" + date + "\n" + addr + "\n";
			String effectiveUserID = httpRequest.getAndRemoveHeader(StorageProperties.StorageParameters.EucaEffectiveUserId.toString());
			try {
				SecurityContext.getLoginContext(new WalrusWrappedComponentCredentials(httpRequest.getCorrelationId(), data, effectiveUserID, signature, certString)).login();
			} catch(Exception ex) {
File
WalrusAuthenticationHandler.java
Developer's decision
Version 2
Kind of conflict
If statement
Method invocation
Try statement
Variable
Chunk
Conflicting content
		catch ( Exception e )
		try
		{
		{
			LOG.error( e, e );
		return result;
	}

<<<<<<< HEAD
	protected String checkSignature( final String queryKey, final String subject ) throws AuthenticationException
	{
		SecretKeySpec signingKey = new SecretKeySpec( queryKey.getBytes(), Hmac.HmacSHA1.toString() );
			Mac mac = Mac.getInstance( Hmac.HmacSHA1.toString() );
			mac.init( signingKey );
			byte[] rawHmac = mac.doFinal( subject.getBytes() );
			return new String(Base64.encode( rawHmac )).replaceAll( "=", "" );
		}
			throw new AuthenticationException( "Failed to compute signature" );
		}
	}

	private void checkUploadPolicy(MappingHttpRequest httpRequest) throws AuthenticationException {
		Map fields = new HashMap();
		String policy = httpRequest.getAndRemoveHeader(WalrusProperties.Headers.S3UploadPolicy.toString());
		fields.put(WalrusProperties.FormField.policy.toString(), policy);
		String policySignature = httpRequest.getAndRemoveHeader(WalrusProperties.Headers.S3UploadPolicySignature.toString());
		if(policySignature == null)
			throw new AuthenticationException("Policy signature must be specified with policy.");
		String awsAccessKeyId = httpRequest.getAndRemoveHeader(SecurityParameter.AWSAccessKeyId.toString());
		if(awsAccessKeyId == null)
			throw new AuthenticationException("AWSAccessKeyID must be specified.");
		fields.put(WalrusProperties.FormField.signature.toString(), policySignature);
		fields.put(SecurityParameter.AWSAccessKeyId.toString(), awsAccessKeyId);
		String acl = httpRequest.getAndRemoveHeader(WalrusProperties.AMZ_ACL.toString());
		if(acl != null)
			fields.put(WalrusProperties.FormField.acl.toString(), acl);
		String operationPath = httpRequest.getServicePath().replaceAll(WalrusProperties.walrusServicePath, "");
		String[] target = WalrusUtil.getTarget(operationPath);
		if(target != null) {
			fields.put(WalrusProperties.FormField.bucket.toString(), target[0]);
			if(target.length > 1)
				fields.put(WalrusProperties.FormField.key.toString(), target[1]);
		}
		UploadPolicyChecker.checkPolicy(httpRequest, fields);

		String data = httpRequest.getAndRemoveHeader(WalrusProperties.FormField.FormUploadPolicyData.toString());
		String auth_part = httpRequest.getAndRemoveHeader(SecurityParameter.Authorization.toString());
		if(auth_part != null) {
			String sigString[] = getSigInfo(auth_part);
			String signature = sigString[1];				
			authenticate(httpRequest, sigString[0], signature, data);
		} else {
			throw new AuthenticationException("User authentication failed. Invalid policy signature.");
		}

	}

=======
>>>>>>> 6178d2cdaf08f808b0652d21fac14474604f4d1b
	@Override
	public void exceptionCaught( final ChannelHandlerContext ctx, final ExceptionEvent exceptionEvent ) throws Exception {
		LOG.info("[exception " + exceptionEvent + "]");
Solution content
		return result;
	}

	private void checkUploadPolicy(MappingHttpRequest httpRequest) throws AuthenticationException {
		Map fields = new HashMap();
		String policy = httpRequest.getAndRemoveHeader(WalrusProperties.Headers.S3UploadPolicy.toString());
		fields.put(WalrusProperties.FormField.policy.toString(), policy);
		String policySignature = httpRequest.getAndRemoveHeader(WalrusProperties.Headers.S3UploadPolicySignature.toString());
		if(policySignature == null)
			throw new AuthenticationException("Policy signature must be specified with policy.");
		String awsAccessKeyId = httpRequest.getAndRemoveHeader(SecurityParameter.AWSAccessKeyId.toString());
		if(awsAccessKeyId == null)
			throw new AuthenticationException("AWSAccessKeyID must be specified.");
		fields.put(WalrusProperties.FormField.signature.toString(), policySignature);
		fields.put(SecurityParameter.AWSAccessKeyId.toString(), awsAccessKeyId);
		String acl = httpRequest.getAndRemoveHeader(WalrusProperties.AMZ_ACL.toString());
		if(acl != null)
			fields.put(WalrusProperties.FormField.acl.toString(), acl);
		String operationPath = httpRequest.getServicePath().replaceAll(WalrusProperties.walrusServicePath, "");
		String[] target = WalrusUtil.getTarget(operationPath);
		if(target != null) {
			fields.put(WalrusProperties.FormField.bucket.toString(), target[0]);
			if(target.length > 1)
				fields.put(WalrusProperties.FormField.key.toString(), target[1]);
		}
		UploadPolicyChecker.checkPolicy(httpRequest, fields);

		String data = httpRequest.getAndRemoveHeader(WalrusProperties.FormField.FormUploadPolicyData.toString());
		String auth_part = httpRequest.getAndRemoveHeader(SecurityParameter.Authorization.toString());
		if(auth_part != null) {
			String sigString[] = getSigInfo(auth_part);
		        if(sigString.length < 2) {
			    throw new AuthenticationException("Invalid authentication header");
			}
			String accessKeyId = sigString[0];
			String signature = sigString[1];
			try {
			    SecurityContext.getLoginContext(new WalrusWrappedCredentials(httpRequest.getCorrelationId(), data, accessKeyId, signature)).login();
			} catch(Exception ex) {
			    LOG.error(ex);
			    throw new AuthenticationException(ex);
			}
		} else {
			throw new AuthenticationException("User authentication failed. Invalid policy signature.");
		}

	}

	@Override
	public void exceptionCaught( final ChannelHandlerContext ctx, final ExceptionEvent exceptionEvent ) throws Exception {
		LOG.info("[exception " + exceptionEvent + "]");
File
WalrusAuthenticationHandler.java
Developer's decision
Manual
Kind of conflict
Method declaration