/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include"signtool.h" #include"zip.h" #include"prmem.h" #include"blapi.h" #include"sechash.h"/* for HASH_GetHashObject() */
/* *SignArchive * *Signanindividualarchivetree.Adirectory *calledMETA-INFiscreatedunderneaththis. *
*/ int
SignArchive(char *tree, char *keyName, char *zip_file, int javascript, char *meta_file, char *install_script, int _optimize, PRBool recurse)
{ int status; char tempfn[FNSIZE], fullfn[FNSIZE];
KeyType keyType = rsaKey; int count;
metafile = meta_file;
optimize = _optimize;
/* To create XPI compatible Archive manifesto() must be run before *thezipfileisopened.Thisissothesignedfilesarenotadded
* the archive before the crucial rsa/dsa file*/ if (xpi_arc) {
manifesto(tree, install_script, recurse);
}
if (zip_file) {
zipfile = JzipOpen(zip_file, NULL /*no comment*/);
}
/*Sign and add files to the archive normally with manifesto()*/ if (!xpi_arc) {
manifesto(tree, install_script, recurse);
}
if (keyName) {
status = create_pk7(tree, keyName, &keyType); if (status < 0) {
PR_fprintf(errorFD, "the tree \"%s\" was NOT SUCCESSFULLY SIGNED\n",
tree);
errorCount++; exit(ERRX);
}
}
/* Add the rsa/dsa file as the first file in the archive. This is crucial
* for a XPInstall compatible archive */ if (xpi_arc) { if (verbosity >= 0) {
PR_fprintf(outputFD, "%s \n", XPI_TEXT);
}
/* rsa/dsa to zip */
count = snprintf(tempfn, sizeof(tempfn), "META-INF/%s.%s", base,
SECKEY_GetKeyTypeString(keyType)); if (count >= sizeof(tempfn)) {
PR_fprintf(errorFD, "unable to write key metadata\n");
errorCount++; exit(ERRX);
}
count = snprintf(fullfn, sizeof(fullfn), "%s/%s", tree, tempfn); if (count >= sizeof(fullfn)) {
PR_fprintf(errorFD, "unable to write key metadata\n");
errorCount++; exit(ERRX);
}
JzipAdd(fullfn, tempfn, zipfile, compression_level);
/* Loop through all files & subdirectories, add to archive */
foreach (tree, "", manifesto_xpi_fn, recurse, PR_FALSE /*include dirs */,
(void *)NULL)
;
} /* mf to zip */
strcpy(tempfn, "META-INF/manifest.mf");
count = snprintf(fullfn, sizeof(fullfn), "%s/%s", tree, tempfn); if (count >= sizeof(fullfn)) {
PR_fprintf(errorFD, "unable to write manifest\n");
errorCount++; exit(ERRX);
}
JzipAdd(fullfn, tempfn, zipfile, compression_level);
/* sf to zip */
count = snprintf(tempfn, sizeof(tempfn), "META-INF/%s.sf", base); if (count >= sizeof(tempfn)) {
PR_fprintf(errorFD, "unable to write sf metadata\n");
errorCount++; exit(ERRX);
}
count = snprintf(fullfn, sizeof(fullfn), "%s/%s", tree, tempfn); if (count >= sizeof(fullfn)) {
PR_fprintf(errorFD, "unable to write sf metadata\n");
errorCount++; exit(ERRX);
}
JzipAdd(fullfn, tempfn, zipfile, compression_level);
/* Add the rsa/dsa file to the zip archive normally */ if (!xpi_arc) { /* rsa/dsa to zip */
count = snprintf(tempfn, sizeof(tempfn), "META-INF/%s.%s", base,
SECKEY_GetKeyTypeString(keyType)); if (count >= sizeof(tempfn)) {
PR_fprintf(errorFD, "unable to write key metadata\n");
errorCount++; exit(ERRX);
}
count = snprintf(fullfn, sizeof(fullfn), "%s/%s", tree, tempfn); if (count >= sizeof(fullfn)) {
PR_fprintf(errorFD, "unable to write key metadata\n");
errorCount++; exit(ERRX);
}
JzipAdd(fullfn, tempfn, zipfile, compression_level);
}
JzipClose(zipfile);
if (verbosity >= 0) { if (javascript) {
PR_fprintf(outputFD, "jarfile \"%s\" signed successfully\n",
zip_file);
} else {
PR_fprintf(outputFD, "tree \"%s\" signed successfully\n",
tree);
}
}
return0;
}
typedefstruct { char *keyName; int javascript; char *metafile; char *install_script; int optimize;
} SignArcInfo;
/* *SignAllArc * *Javascriptmaygeneratemultiple.arcdirectories,one *foreachjararchiveneeded.Signthemall. *
*/ int
SignAllArc(char *jartree, char *keyName, int javascript, char *metafilename, char *install_script, int optimize_level, PRBool recurse)
{
SignArcInfo info;
/* Make sure there is one and only one ".arc" in the relative path,
* and that it is at the end of the path (don't sign .arcs within .arcs) */ if ((PL_strcaserstr(relpath, ".arc") == relpath + strlen(relpath) - 4) &&
(PL_strcasestr(relpath, ".arc") == relpath + strlen(relpath) - 4)) {
/* Create the META-INF directory to hold signing info */
if (PR_Access(dirname, PR_ACCESS_READ_OK)) {
PR_fprintf(errorFD, "%s: unable to read your directory: %s\n",
PROGRAM_NAME, dirname);
errorCount++;
perror(dirname); exit(ERRX);
}
if (PR_Access(dirname, PR_ACCESS_WRITE_OK)) {
PR_fprintf(errorFD, "%s: unable to write to your directory: %s\n",
PROGRAM_NAME, dirname);
errorCount++;
perror(dirname); exit(ERRX);
}
if ((mf = fopen(metadir, "wb")) == NULL) {
perror(MANIFEST);
PR_fprintf(errorFD, "%s: Probably, the directory you are trying to" " sign has\n",
PROGRAM_NAME);
PR_fprintf(errorFD, "%s: permissions problems or may not exist.\n",
PROGRAM_NAME);
errorCount++; exit(ERRX);
}
if (scriptdir) {
fprintf(mf, "Comments: --\n");
fprintf(mf, "Comments: --\n");
fprintf(mf, "Comments: -- This archive signs Javascripts which may not necessarily\n");
fprintf(mf, "Comments: -- be included in the physical jar file.\n");
fprintf(mf, "Comments: --\n");
fprintf(mf, "Comments: --\n");
}
if (install_script)
fprintf(mf, "Install-Script: %s\n", install_script);
if (metafile)
add_meta(mf, "+");
/* Loop through all files & subdirectories */
foreach (dirname, "", manifesto_fn, recurse, PR_FALSE /*include dirs */,
(void *)NULL)
;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.