/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* <p>A signature file as defined in the <a
* href="manifest.html">Manifest and Signature Format</a>. It has
* essentially the same structure as a Manifest file in that it is a
* set of RFC 822 headers (sections). The first section contains meta
* data relevant to the entire file (i.e "Signature-Version:1.0") and
* each subsequent section contains data relevant to specific entries:
* entry sections.
*
* <p>Each entry section contains the name of an entry (which must
* have a counterpart in the manifest). Like the manifest it contains
* a hash, the hash of the manifest section correspondind to the
* name. Since the manifest entry contains the hash of the data, this
* is equivalent to a signature of the data, plus the attributes of
* the manifest entry.
*
* <p>This signature file format deal with PKCS7 encoded DSA signature
* block. It should be straightforward to extent to support other
* algorithms.
*
* @author David Brown
* @author Benjamin Renaud */
public class SignatureFile {
/* Are we debugging? */
static final boolean debug = false;
/* list of headers that all pertain to a particular file in the
* archive */
/* Right now we only support SHA hashes */
if (debug)
}
/*
* The manifest we're working with. */
/*
* The file name for the file. This is the raw name, i.e. the
* extention-less 8 character name (such as MYSIGN) which wil be
* used to build the signature filename (MYSIGN.SF) and the block
* filename (MYSIGN.DSA) */
/* The digital signature block corresponding to this signature
* file. */
/**
* Private constructor which takes a name a given signature
* file. The name must be extension-less and less or equal to 8
* character in length. */
throw new JarException("invalid file name");
}
}
}
/**
* Private constructor which takes a name a given signature file
* and a new file predicate. If it is a new file, a main header
* will be added. */
throws JarException {
this(name);
if (newFile) {
}
}
/**
* Constructs a new Signature file corresponding to a given
* Manifest. All entries in the manifest are signed.
*
* @param manifest the manifest to use.
*
* @param name for this signature file. This should
* be less than 8 characters, and without a suffix (i.e.
* without a period in it.
*
* @exception JarException if an invalid name is passed in.
*/
throws JarException {
this(name, true);
while (enum_.hasMoreElements()) {
}
}
}
/**
* Constructs a new Signature file corresponding to a given
* Manifest. Specific entries in the manifest are signed.
*
* @param manifest the manifest to use.
*
* @param entries the entries to sign.
*
* @param filename for this signature file. This should
* be less than 8 characters, and without a suffix (i.e.
* without a period in it.
*
* @exception JarException if an invalid name is passed in.
*/
throws JarException {
this(filename, true);
}
/**
* Construct a Signature file from an input stream.
*
* @exception IOException if an invalid name is passed in or if a
* stream exception occurs.
*/
throws IOException {
this(filename);
entries.addElement(m);
}
}
/**
* Construct a Signature file from an input stream.
*
* @exception IOException if an invalid name is passed in or if a
* stream exception occurs.
*/
}
this(new ByteArrayInputStream(bytes));
}
/**
* Returns the name of the signature file, ending with a ".SF"
* suffix */
}
/**
* Returns the name of the block file, ending with a block suffix
* such as ".DSA". */
if (signatureBlock != null) {
}
}
/**
* Returns the signature block associated with this file.
*/
return signatureBlock;
}
/**
* Sets the signature block associated with this file.
*/
this.signatureBlock = block;
}
/**
* Add a set of entries from the current manifest.
*/
}
}
/**
* Add a specific entry from the current manifest.
*/
}
try {
} catch (IOException e) {
throw new JarException(e.getMessage());
}
}
/**
* Get the entry corresponding to a given name. Returns null if
*the entry does not exist.
*/
while(enum_.hasMoreElements()) {
return mh;
}
}
return null;
}
/**
* Returns the n-th entry. The global header is a entry 0. */
}
/**
* Returns an enumeration of the entries.
*/
}
/**
* Given a manifest entry, computes the signature entry for this
* manifest entry.
*/
return null;
}
try {
}
return smh;
} catch (NoSuchAlgorithmException e) {
throw new JarException(e.getMessage());
}
}
throws NoSuchAlgorithmException {
}
return dig;
}
/**
* Add a signature file at current position in a stream
*/
/* the first header in the file should be the global one.
* It should say "SignatureFile-Version: x.x"; barf if not
*/
throw new JarException("Signature file requires " +
"Signature-Version: 1.0 in 1st header");
}
}
}
}