Source Code Cross Referenced for MultipartSignedRenderer.java in  » Mail-Clients » columba-1.4 » org » columba » mail » pgp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Mail Clients » columba 1.4 » org.columba.mail.pgp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //The contents of this file are subject to the Mozilla Public License Version 1.1
002:        //(the "License"); you may not use this file except in compliance with the 
003:        //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004:        //
005:        //Software distributed under the License is distributed on an "AS IS" basis,
006:        //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
007:        //for the specific language governing rights and
008:        //limitations under the License.
009:        //
010:        //The Original Code is "The Columba Project"
011:        //
012:        //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013:        //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003. 
014:        //
015:        //All Rights Reserved.
016:        package org.columba.mail.pgp;
017:
018:        import java.io.ByteArrayInputStream;
019:        import java.io.InputStream;
020:        import java.util.Vector;
021:
022:        import org.columba.core.io.CloneStreamMaster;
023:        import org.columba.ristretto.composer.MimePartRenderer;
024:        import org.columba.ristretto.composer.MimeTreeRenderer;
025:        import org.columba.ristretto.io.SequenceInputStream;
026:        import org.columba.ristretto.message.InputStreamMimePart;
027:        import org.columba.ristretto.message.MimeHeader;
028:        import org.columba.ristretto.message.MimePart;
029:        import org.columba.ristretto.message.StreamableMimePart;
030:        import org.waffel.jscf.JSCFConnection;
031:        import org.waffel.jscf.JSCFResultSet;
032:        import org.waffel.jscf.JSCFStatement;
033:
034:        /**
035:         * @author waffel
036:         * 
037:         * This class renders a message to be a signed message. The class supports
038:         * currently only pgp as method.
039:         */
040:        public class MultipartSignedRenderer extends MimePartRenderer {
041:            private MimeHeader signatureHeader;
042:
043:            /**
044:             * Creates a new Instance to render a message which should be signed. This
045:             * constructor initialize the header for the signature with new mime header
046:             * <code>application</code> and the value <code>pgp-signature</code>
047:             */
048:            public MultipartSignedRenderer() {
049:                this .signatureHeader = new MimeHeader("application",
050:                        "pgp-signature");
051:            }
052:
053:            /*
054:             * (non-Javadoc)
055:             * 
056:             * @see org.columba.ristretto.composer.MimePartRenderer#getRegisterString()
057:             */
058:            public String getRegisterString() {
059:                return "multipart/signed";
060:            }
061:
062:            /*
063:             * (non-Javadoc)
064:             * 
065:             * @see org.columba.ristretto.composer.MimePartRenderer#render(org.columba.ristretto.message.StreamableMimePart)
066:             */
067:            public InputStream render(MimePart part) throws Exception {
068:                Vector streams = new Vector((2 * 2) + 3);
069:
070:                MimeHeader header = part.getHeader();
071:
072:                // Create boundary to separate the mime-parts
073:                String boundary = createUniqueBoundary().toString();
074:                header.putContentParameter("boundary", boundary);
075:
076:                byte[] startBoundary = ("\r\n--" + boundary + "\r\n")
077:                        .getBytes();
078:                byte[] endBoundary = ("\r\n--" + boundary + "--\r\n")
079:                        .getBytes();
080:
081:                // Add pgp-specific content-parameters
082:                // we take as default hash-algo SHA1
083:                header.putContentParameter("micalg", "pgp-sha1");
084:                header.putContentParameter("protocol",
085:                        "application/pgp-signature");
086:
087:                // Create the header and body of the multipart
088:                streams.add(header.getHeader().getInputStream());
089:
090:                // Add the MimePart that will be signed
091:                streams.add(new ByteArrayInputStream(startBoundary));
092:
093:                CloneStreamMaster signedPartCloneModel = new CloneStreamMaster(
094:                        MimeTreeRenderer.getInstance().renderMimePart(
095:                                part.getChild(0)));
096:
097:                streams.add(signedPartCloneModel.getClone());
098:
099:                // Add the signature
100:                streams.add(new ByteArrayInputStream(startBoundary));
101:
102:                StreamableMimePart signatureMimePart;
103:
104:                signatureMimePart = null;
105:
106:                JSCFController controller = JSCFController.getInstance();
107:                JSCFConnection con = controller.getConnection();
108:
109:                PGPPassChecker passCheck = PGPPassChecker.getInstance();
110:                boolean check = passCheck.checkPassphrase(con);
111:
112:                if (!check) {
113:                    throw new WrongPassphraseException("wrong passphrase");
114:                }
115:
116:                JSCFStatement stmt = con.createStatement();
117:                JSCFResultSet res = stmt.executeSign(signedPartCloneModel
118:                        .getClone());
119:
120:                signatureMimePart = new InputStreamMimePart(
121:                        this .signatureHeader, res.getResultStream());
122:
123:                streams.add(MimeTreeRenderer.getInstance().renderMimePart(
124:                        signatureMimePart));
125:
126:                // Create the closing boundary
127:                streams.add(new ByteArrayInputStream(endBoundary));
128:
129:                return new SequenceInputStream(streams);
130:            }
131:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.