Program: 106470
Project: 106470
Buggy source:
/** 
 * This function implements the EC2 REST authentication algorithm.   It uses the given "AWSAccessKeyId" parameter to look up the Cloud.com account holder's secret key which is used as input to the signature calculation.  In addition, it tests the given "Expires" parameter to see if the signature has expired and if so the request fails.
 */
private boolean authenticateRequest(HttpServletRequest request,HttpServletResponse response) throws SignatureException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, ParseException {
  String cloudSecretKey=null;
  String cloudAccessKey=null;
  String signature=null;
  String sigMethod=null;
  String[] awsAccess=request.getParameterValues("String_Node_Str");
  if (null != awsAccess && 0 < awsAccess.length)   cloudAccessKey=awsAccess[0];
 else {
    response.sendError(530,"String_Node_Str");
    return false;
  }
  String[] clientSig=request.getParameterValues("String_Node_Str");
  if (null != clientSig && 0 < clientSig.length)   signature=clientSig[0];
 else {
    response.sendError(530,"String_Node_Str");
    return false;
  }
  String[] method=request.getParameterValues("String_Node_Str");
  if (null != method && 0 < method.length) {
    sigMethod=method[0];
    if (!sigMethod.equals("String_Node_Str") && !sigMethod.equals("String_Node_Str")) {
      response.sendError(531,"String_Node_Str" + sigMethod + "String_Node_Str");
      return false;
    }
  }
 else {
    response.sendError(530,"String_Node_Str");
    return false;
  }
  String[] version=request.getParameterValues("String_Node_Str");
  if (null != version && 0 < version.length) {
    if (!version[0].equals(wsdlVersion)) {
      response.sendError(531,"String_Node_Str" + version[0] + "String_Node_Str"+ wsdlVersion);
      return false;
    }
  }
 else {
    response.sendError(530,"String_Node_Str");
    return false;
  }
  String[] sigVersion=request.getParameterValues("String_Node_Str");
  if (null != sigVersion && 0 < sigVersion.length) {
    if (!sigVersion[0].equals("String_Node_Str")) {
      response.sendError(531,"String_Node_Str" + sigVersion[0] + "String_Node_Str");
      return false;
    }
  }
 else {
    response.sendError(530,"String_Node_Str");
    return false;
  }
  String[] expires=request.getParameterValues("String_Node_Str");
  if (null != expires && 0 < expires.length) {
    if (hasSignatureExpired(expires[0])) {
      response.sendError(531,"String_Node_Str" + expires[0]);
      return false;
    }
  }
 else {
    String[] time=request.getParameterValues("String_Node_Str");
    if (null == time || 0 == time.length) {
      response.sendError(530,"String_Node_Str");
      return false;
    }
  }
  UserCredentialsDao credentialDao=new UserCredentialsDao();
  UserCredentials cloudKeys=credentialDao.getByAccessKey(cloudAccessKey);
  if (null == cloudKeys) {
    logger.debug(cloudAccessKey + "String_Node_Str");
    response.sendError(404,cloudAccessKey + "String_Node_Str");
    return false;
  }
 else   cloudSecretKey=cloudKeys.getSecretKey();
  EC2RestAuth restAuth=new EC2RestAuth();
  restAuth.setHostHeader(request.getHeader("String_Node_Str"));
  String requestUri=request.getRequestURI();
  String forwardedPath=(String)request.getAttribute("String_Node_Str");
  if (forwardedPath != null) {
    requestUri=forwardedPath;
  }
  restAuth.setHTTPRequestURI(requestUri);
  restAuth.setQueryString(request.getQueryString());
  if (restAuth.verifySignature(request.getMethod(),cloudSecretKey,signature,sigMethod)) {
    UserContext.current().initContext(cloudAccessKey,cloudSecretKey,cloudAccessKey,"String_Node_Str",null);
    return true;
  }
 else   throw new PermissionDeniedException("String_Node_Str");
}

Fixed version (ground truth):
/** 
 * This function implements the EC2 REST authentication algorithm.   It uses the given "AWSAccessKeyId" parameter to look up the Cloud.com account holder's secret key which is used as input to the signature calculation.  In addition, it tests the given "Expires" parameter to see if the signature has expired and if so the request fails.
 */
private boolean authenticateRequest(HttpServletRequest request,HttpServletResponse response) throws SignatureException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, ParseException {
  String cloudSecretKey=null;
  String cloudAccessKey=null;
  String signature=null;
  String sigMethod=null;
  String[] awsAccess=request.getParameterValues("String_Node_Str");
  if (null != awsAccess && 0 < awsAccess.length)   cloudAccessKey=awsAccess[0];
 else {
    response.sendError(530,"String_Node_Str");
    return false;
  }
  String[] clientSig=request.getParameterValues("String_Node_Str");
  if (null != clientSig && 0 < clientSig.length)   signature=clientSig[0];
 else {
    response.sendError(530,"String_Node_Str");
    return false;
  }
  String[] method=request.getParameterValues("String_Node_Str");
  if (null != method && 0 < method.length) {
    sigMethod=method[0];
    if (!sigMethod.equals("String_Node_Str") && !sigMethod.equals("String_Node_Str")) {
      response.sendError(531,"String_Node_Str" + sigMethod + "String_Node_Str");
      return false;
    }
  }
 else {
    response.sendError(530,"String_Node_Str");
    return false;
  }
  String[] version=request.getParameterValues("String_Node_Str");
  if (null != version && 0 < version.length) {
    if (!version[0].equals(wsdlVersion)) {
      response.sendError(531,"String_Node_Str" + version[0] + "String_Node_Str"+ wsdlVersion);
      return false;
    }
  }
 else {
    response.sendError(530,"String_Node_Str");
    return false;
  }
  String[] sigVersion=request.getParameterValues("String_Node_Str");
  if (null != sigVersion && 0 < sigVersion.length) {
    if (!sigVersion[0].equals("String_Node_Str")) {
      response.sendError(531,"String_Node_Str" + sigVersion[0] + "String_Node_Str");
      return false;
    }
  }
 else {
    response.sendError(530,"String_Node_Str");
    return false;
  }
  String[] expires=request.getParameterValues("String_Node_Str");
  if (null != expires && 0 < expires.length) {
    if (hasSignatureExpired(expires[0])) {
      response.sendError(531,"String_Node_Str" + expires[0]);
      return false;
    }
  }
 else {
    String[] time=request.getParameterValues("String_Node_Str");
    if (null == time || 0 == time.length) {
      response.sendError(530,"String_Node_Str");
      return false;
    }
  }
  UserCredentialsDao credentialDao=new UserCredentialsDao();
  UserCredentials cloudKeys=credentialDao.getByAccessKey(cloudAccessKey);
  if (null == cloudKeys) {
    logger.debug(cloudAccessKey + "String_Node_Str");
    response.sendError(404,cloudAccessKey + "String_Node_Str");
    return false;
  }
 else   cloudSecretKey=cloudKeys.getSecretKey();
  EC2RestAuth restAuth=new EC2RestAuth();
  restAuth.setHostHeader(request.getHeader("String_Node_Str"));
  String requestUri=request.getRequestURI();
  String forwardedPath=(String)request.getAttribute("String_Node_Str");
  if (forwardedPath != null) {
    requestUri=forwardedPath;
  }
  restAuth.setHTTPRequestURI(requestUri);
  String queryString=request.getQueryString();
  if (queryString == null) {
    Enumeration<?> params=request.getParameterNames();
    if (params != null) {
      while (params.hasMoreElements()) {
        String paramName=(String)params.nextElement();
        if (paramName.equalsIgnoreCase("String_Node_Str"))         continue;
        if (queryString == null)         queryString=paramName + "String_Node_Str" + request.getParameter(paramName);
 else         queryString=queryString + "String_Node_Str" + paramName+ "String_Node_Str"+ URLEncoder.encode(request.getParameter(paramName),"String_Node_Str");
      }
    }
  }
  restAuth.setQueryString(queryString);
  if (restAuth.verifySignature(request.getMethod(),cloudSecretKey,signature,sigMethod)) {
    UserContext.current().initContext(cloudAccessKey,cloudSecretKey,cloudAccessKey,"String_Node_Str",null);
    return true;
  }
 else   throw new PermissionDeniedException("String_Node_Str");
}