예제 #1
0
 /*     */ private Object nextMatch() /*     */ {
   /*  85 */ while (this.iterator.hasNext()) {
     /*  86 */ MimeHeader mimeheader = (MimeHeader) this.iterator.next();
     /*     */
     /*  88 */ if (this.names == null) {
       /*  89 */ return ((this.match) ? null : mimeheader);
       /*     */ }
     /*     */
     /*  94 */ for (int i = 0; i < this.names.length; ++i) {
       /*  95 */ if (!(mimeheader.getName().equalsIgnoreCase(this.names[i]))) {
         /*     */ continue;
         /*     */ }
       /*     */
       /*  99 */ if (!(this.match)) break;
       /* 100 */ return mimeheader;
       /*     */ }
     /*     */
     /* 106 */ label90:
     if (!(this.match)) {
       /* 107 */ return mimeheader;
       /*     */ }
     /*     */ }
   /*     */
   /* 111 */ return null;
   /*     */ }
예제 #2
0
 /*     */ public void removeHeader(String name) /*     */ {
   /* 311 */ for (int i = 0; i < this.headers.size(); ++i) {
     /* 312 */ MimeHeader mimeheader = (MimeHeader) this.headers.elementAt(i);
     /*     */
     /* 314 */ if (mimeheader.getName().equalsIgnoreCase(name))
       /* 315 */ this.headers.removeElementAt(i--);
     /*     */ }
   /*     */ }
예제 #3
0
 private MimePart transferMessageHeaders(MimePart newBody) {
   for (Iterator<MimeHeader> it = body.getMimeHeaderBlock().iterator(); it.hasNext(); ) {
     MimeHeader header = it.next();
     String lcname = header.getName().toLowerCase();
     if (!lcname.equals("content-type") && !lcname.equals("content-transfer-encoding")) {
       // FIXME: want to have the new body's old headers at the *end* of the resulting list, not at
       // the beginning
       newBody.addMimeHeader(header);
       it.remove();
     }
   }
   return newBody;
 }
예제 #4
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;
  }
예제 #5
0
 /*     */ public void addHeader(String name, String value) /*     */ {
   /* 283 */ if ((name == null) || (name.equals(""))) {
     /* 284 */ throw new IllegalArgumentException("Illegal MimeHeader name");
     /*     */ }
   /*     */
   /* 288 */ int i = this.headers.size();
   /*     */
   /* 290 */ for (int j = i - 1; j >= 0; --j) {
     /* 291 */ MimeHeader mimeheader = (MimeHeader) this.headers.elementAt(j);
     /*     */
     /* 293 */ if (mimeheader.getName().equalsIgnoreCase(name)) {
       /* 294 */ this.headers.insertElementAt(new MimeHeader(name, value), j + 1);
       /*     */
       /* 296 */ return;
       /*     */ }
     /*     */ }
   /*     */
   /* 300 */ this.headers.addElement(new MimeHeader(name, value));
   /*     */ }
예제 #6
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;
   /*     */ }
예제 #7
0
 /*     */ public void setHeader(String name, String value) /*     */ {
   /* 239 */ boolean flag = false;
   /*     */
   /* 241 */ if ((name == null) || (name.equals(""))) {
     /* 242 */ throw new IllegalArgumentException("Illegal MimeHeader name");
     /*     */ }
   /*     */
   /* 246 */ for (int i = 0; i < this.headers.size(); ++i) {
     /* 247 */ MimeHeader mimeheader = (MimeHeader) this.headers.elementAt(i);
     /*     */
     /* 249 */ if (mimeheader.getName().equalsIgnoreCase(name)) {
       /* 250 */ if (!(flag)) {
         /* 251 */ this.headers.setElementAt(new MimeHeader(mimeheader.getName(), value), i);
         /*     */
         /* 254 */ flag = true;
         /*     */ } else {
         /* 256 */ this.headers.removeElementAt(i--);
         /*     */ }
       /*     */ }
     /*     */ }
   /*     */
   /* 261 */ if (!(flag)) /* 262 */ addHeader(name, value);
   /*     */ }
예제 #8
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);
  }
예제 #9
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;
  }