Пример #1
0
 /*     */ public String[] getHeader(String name) /*     */ {
   /* 198 */ Vector vector = new Vector();
   /*     */
   /* 200 */ for (int i = 0; i < this.headers.size(); ++i) {
     /* 201 */ MimeHeader mimeheader = (MimeHeader) this.headers.elementAt(i);
     /*     */
     /* 203 */ if ((!(mimeheader.getName().equalsIgnoreCase(name)))
         || (mimeheader.getValue() == null)) /*     */ continue;
     /* 205 */ vector.addElement(mimeheader.getValue());
     /*     */ }
   /*     */
   /* 209 */ if (vector.size() == 0) {
     /* 210 */ return null;
     /*     */ }
   /* 212 */ String[] as = new String[vector.size()];
   /*     */
   /* 214 */ vector.copyInto(as);
   /*     */
   /* 216 */ return as;
   /*     */ }
Пример #2
0
  public MimeContentType getContentType() {
    MimeContentType ct = super.getContentType();
    if (startBodyPart_ != null) {
      MimeContentType startCt = startBodyPart_.getContentType();
      MimeHeader startCid = startBodyPart_.getHeader("content-id");

      // Add content-type
      ct.setParam("type", startCt.getValue());

      // Add start parameter
      if (startCid != null) {
        ct.setParam("start", startCid.getValue());
      }
    }
    return ct;
  }
Пример #3
0
  /* c: SMIME_read_PKCS7
   *
   */
  public PKCS7 readPKCS7(BIO bio, BIO[] bcont) throws IOException, PKCS7Exception {
    if (bcont != null && bcont.length > 0) {
      bcont[0] = null;
    }

    List<MimeHeader> headers = mime.parseHeaders(bio);
    if (headers == null) {
      throw new PKCS7Exception(PKCS7.F_SMIME_READ_PKCS7, PKCS7.R_MIME_PARSE_ERROR);
    }

    MimeHeader hdr = mime.findHeader(headers, "content-type");
    if (hdr == null || hdr.getValue() == null) {
      throw new PKCS7Exception(PKCS7.F_SMIME_READ_PKCS7, PKCS7.R_NO_CONTENT_TYPE);
    }

    if ("multipart/signed".equals(hdr.getValue())) {
      MimeParam prm = mime.findParam(hdr, "boundary");
      if (prm == null || prm.getParamValue() == null) {
        throw new PKCS7Exception(PKCS7.F_SMIME_READ_PKCS7, PKCS7.R_NO_MULTIPART_BOUNDARY);
      }

      byte[] boundary = null;
      try {
        boundary = prm.getParamValue().getBytes("ISO8859-1");
      } catch (Exception e) {
        throw new PKCS7Exception(PKCS7.F_SMIME_READ_PKCS7, PKCS7.R_NO_MULTIPART_BOUNDARY);
      }

      List<BIO> parts = multiSplit(bio, boundary);
      if (parts == null || parts.size() != 2) {
        throw new PKCS7Exception(PKCS7.F_SMIME_READ_PKCS7, PKCS7.R_NO_MULTIPART_BODY_FAILURE);
      }

      BIO p7in = parts.get(1);

      headers = mime.parseHeaders(p7in);

      if (headers == null) {
        throw new PKCS7Exception(PKCS7.F_SMIME_READ_PKCS7, PKCS7.R_MIME_SIG_PARSE_ERROR);
      }

      hdr = mime.findHeader(headers, "content-type");
      if (hdr == null || hdr.getValue() == null) {
        throw new PKCS7Exception(PKCS7.F_SMIME_READ_PKCS7, PKCS7.R_NO_SIG_CONTENT_TYPE);
      }

      if (!"application/x-pkcs7-signature".equals(hdr.getValue())
          && !"application/pkcs7-signature".equals(hdr.getValue())
          && !"application/x-pkcs7-mime".equals(hdr.getValue())
          && !"application/pkcs7-mime".equals(hdr.getValue())) {
        throw new PKCS7Exception(
            PKCS7.F_SMIME_READ_PKCS7, PKCS7.R_SIG_INVALID_MIME_TYPE, "type: " + hdr.getValue());
      }

      PKCS7 p7 = readPKCS7Base64(p7in);

      if (bcont != null && bcont.length > 0) {
        bcont[0] = parts.get(0);
      }

      return p7;
    }

    if (!"application/x-pkcs7-mime".equals(hdr.getValue())
        && !"application/pkcs7-mime".equals(hdr.getValue())) {
      throw new PKCS7Exception(
          PKCS7.F_SMIME_READ_PKCS7, PKCS7.R_INVALID_MIME_TYPE, "type: " + hdr.getValue());
    }

    return readPKCS7Base64(bio);
  }
Пример #4
0
  SOAPMessage post(SOAPMessage message, URL endPoint) throws SOAPException {
    boolean isFailure = false;

    URL url = null;
    HttpURLConnection httpConnection = null;

    int responseCode = 0;
    try {
      if (endPoint.getProtocol().equals("https"))
        // if(!setHttps)
        initHttps();
      // Process the URL
      JaxmURI uri = new JaxmURI(endPoint.toString());
      String userInfo = uri.getUserinfo();

      url = endPoint;

      if (dL > 0) d("uri: " + userInfo + " " + url + " " + uri);

      // TBD
      //    Will deal with https later.
      if (!url.getProtocol().equalsIgnoreCase("http")
          && !url.getProtocol().equalsIgnoreCase("https")) {
        log.severe("SAAJ0052.p2p.protocol.mustbe.http.or.https");
        throw new IllegalArgumentException(
            "Protocol " + url.getProtocol() + " not supported in URL " + url);
      }
      httpConnection = (HttpURLConnection) createConnection(url);

      httpConnection.setRequestMethod("POST");

      httpConnection.setDoOutput(true);
      httpConnection.setDoInput(true);
      httpConnection.setUseCaches(false);
      httpConnection.setInstanceFollowRedirects(true);

      if (message.saveRequired()) message.saveChanges();

      MimeHeaders headers = message.getMimeHeaders();

      Iterator it = headers.getAllHeaders();
      boolean hasAuth = false; // true if we find explicit Auth header
      while (it.hasNext()) {
        MimeHeader header = (MimeHeader) it.next();

        String[] values = headers.getHeader(header.getName());
        if (values.length == 1)
          httpConnection.setRequestProperty(header.getName(), header.getValue());
        else {
          StringBuffer concat = new StringBuffer();
          int i = 0;
          while (i < values.length) {
            if (i != 0) concat.append(',');
            concat.append(values[i]);
            i++;
          }

          httpConnection.setRequestProperty(header.getName(), concat.toString());
        }

        if ("Authorization".equals(header.getName())) {
          hasAuth = true;
          log.fine("SAAJ0091.p2p.https.auth.in.POST.true");
        }
      }

      if (!hasAuth && userInfo != null) {
        initAuthUserInfo(httpConnection, userInfo);
      }

      OutputStream out = httpConnection.getOutputStream();
      message.writeTo(out);

      out.flush();
      out.close();

      httpConnection.connect();

      try {

        responseCode = httpConnection.getResponseCode();

        // let HTTP_INTERNAL_ERROR (500) through because it is used for SOAP faults
        if (responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR) {
          isFailure = true;
        }
        // else if (responseCode != HttpURLConnection.HTTP_OK)
        // else if (!(responseCode >= HttpURLConnection.HTTP_OK && responseCode < 207))
        else if ((responseCode / 100) != 2) {
          log.log(
              Level.SEVERE,
              "SAAJ0008.p2p.bad.response",
              new String[] {httpConnection.getResponseMessage()});
          throw new SOAPExceptionImpl(
              "Bad response: (" + responseCode + httpConnection.getResponseMessage());
        }
      } catch (IOException e) {
        // on JDK1.3.1_01, we end up here, but then getResponseCode() succeeds!
        responseCode = httpConnection.getResponseCode();
        if (responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR) {
          isFailure = true;
        } else {
          throw e;
        }
      }

    } catch (SOAPException ex) {
      throw ex;
    } catch (Exception ex) {
      log.severe("SAAJ0009.p2p.msg.send.failed");
      throw new SOAPExceptionImpl("Message send failed", ex);
    }

    SOAPMessage response = null;
    if (responseCode == HttpURLConnection.HTTP_OK || isFailure) {
      try {
        MimeHeaders headers = new MimeHeaders();

        String key, value;

        // Header field 0 is the status line so we skip it.

        int i = 1;

        while (true) {
          key = httpConnection.getHeaderFieldKey(i);
          value = httpConnection.getHeaderField(i);

          if (key == null && value == null) break;

          if (key != null) {
            StringTokenizer values = new StringTokenizer(value, ",");
            while (values.hasMoreTokens()) headers.addHeader(key, values.nextToken().trim());
          }
          i++;
        }

        InputStream httpIn =
            (isFailure ? httpConnection.getErrorStream() : httpConnection.getInputStream());

        byte[] bytes = readFully(httpIn);

        int length =
            httpConnection.getContentLength() == -1
                ? bytes.length
                : httpConnection.getContentLength();

        // If no reply message is returned,
        // content-Length header field value is expected to be zero.
        if (length == 0) {
          response = null;
          log.warning("SAAJ0014.p2p.content.zero");
        } else {
          ByteInputStream in = new ByteInputStream(bytes, length);
          response = messageFactory.createMessage(headers, in);
        }

        httpIn.close();
        httpConnection.disconnect();

      } catch (SOAPException ex) {
        throw ex;
      } catch (Exception ex) {
        log.log(Level.SEVERE, "SAAJ0010.p2p.cannot.read.resp", ex);
        throw new SOAPExceptionImpl("Unable to read response: " + ex.getMessage());
      }
    }
    return response;
  }