2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef nsJAR_h__
|
|
|
|
#define nsJAR_h__
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "prio.h"
|
|
|
|
#include "plstr.h"
|
|
|
|
#include "prlog.h"
|
|
|
|
#include "prinrval.h"
|
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-03-31 21:29:02 -07:00
|
|
|
#include "mozilla/Mutex.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2014-02-25 20:32:48 -08:00
|
|
|
#include "nsClassHashtable.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIFile.h"
|
|
|
|
#include "nsStringEnumerator.h"
|
2014-02-24 17:16:11 -08:00
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
#include "nsTHashtable.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIZipReader.h"
|
|
|
|
#include "nsZipArchive.h"
|
2012-10-21 23:29:56 -07:00
|
|
|
#include "nsICertificatePrincipal.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsISignatureVerifier.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsIObserver.h"
|
2012-06-12 20:27:07 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsIInputStream;
|
|
|
|
class nsJARManifestItem;
|
|
|
|
class nsZipReaderCache;
|
|
|
|
|
|
|
|
/* For mManifestStatus */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
JAR_MANIFEST_NOT_PARSED = 0,
|
|
|
|
JAR_VALID_MANIFEST = 1,
|
|
|
|
JAR_INVALID_SIG = 2,
|
|
|
|
JAR_INVALID_UNKNOWN_CA = 3,
|
|
|
|
JAR_INVALID_MANIFEST = 4,
|
|
|
|
JAR_INVALID_ENTRY = 5,
|
|
|
|
JAR_NO_MANIFEST = 6,
|
|
|
|
JAR_NOT_SIGNED = 7
|
|
|
|
} JARManifestStatusType;
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2014-02-24 17:16:11 -08:00
|
|
|
* Class nsJAR declaration.
|
|
|
|
* nsJAR serves as an XPCOM wrapper for nsZipArchive with the addition of
|
|
|
|
* JAR manifest file parsing.
|
2007-03-22 10:30:00 -07:00
|
|
|
*------------------------------------------------------------------------*/
|
2010-03-07 05:56:45 -08:00
|
|
|
class nsJAR : public nsIZipReader
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Allows nsJARInputStream to call the verification functions
|
|
|
|
friend class nsJARInputStream;
|
2010-09-08 20:38:34 -07:00
|
|
|
// Allows nsZipReaderCache to access mOuterZipEntry
|
|
|
|
friend class nsZipReaderCache;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
nsJAR();
|
|
|
|
virtual ~nsJAR();
|
2014-02-24 17:16:11 -08:00
|
|
|
|
2007-04-23 07:21:53 -07:00
|
|
|
NS_DEFINE_STATIC_CID_ACCESSOR( NS_ZIPREADER_CID )
|
2014-02-24 17:16:11 -08:00
|
|
|
|
2013-07-18 19:23:44 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_DECL_NSIZIPREADER
|
|
|
|
|
|
|
|
nsresult GetJarPath(nsACString& aResult);
|
|
|
|
|
|
|
|
PRIntervalTime GetReleaseTime() {
|
|
|
|
return mReleaseTime;
|
|
|
|
}
|
2014-02-24 17:16:11 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsReleased() {
|
2007-03-22 10:30:00 -07:00
|
|
|
return mReleaseTime != PR_INTERVAL_NO_TIMEOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetReleaseTime() {
|
|
|
|
mReleaseTime = PR_IntervalNow();
|
|
|
|
}
|
2014-02-24 17:16:11 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void ClearReleaseTime() {
|
|
|
|
mReleaseTime = PR_INTERVAL_NO_TIMEOUT;
|
|
|
|
}
|
2014-02-24 17:16:11 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void SetZipReaderCache(nsZipReaderCache* cache) {
|
|
|
|
mCache = cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-02-25 20:32:48 -08:00
|
|
|
typedef nsClassHashtable<nsCStringHashKey, nsJARManifestItem> ManifestDataHashtable;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-- Private data members
|
|
|
|
nsCOMPtr<nsIFile> mZipFile; // The zip/jar file on disk
|
2010-09-08 20:38:34 -07:00
|
|
|
nsCString mOuterZipEntry; // The entry in the zip this zip is reading from
|
2011-12-08 02:03:36 -08:00
|
|
|
nsRefPtr<nsZipArchive> mZip; // The underlying zip archive
|
2014-02-25 20:32:48 -08:00
|
|
|
ManifestDataHashtable mManifestData; // Stores metadata for each entry
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mParsedManifest; // True if manifest has been parsed
|
2012-10-21 23:29:56 -07:00
|
|
|
nsCOMPtr<nsICertificatePrincipal> mPrincipal; // The entity which signed this file
|
2012-08-22 08:56:38 -07:00
|
|
|
int16_t mGlobalStatus; // Global signature verification status
|
2007-03-22 10:30:00 -07:00
|
|
|
PRIntervalTime mReleaseTime; // used by nsZipReaderCache for flushing entries
|
|
|
|
nsZipReaderCache* mCache; // if cached, this points to the cache it's contained in
|
2014-02-24 17:16:11 -08:00
|
|
|
mozilla::Mutex mLock;
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mMtime;
|
|
|
|
int32_t mTotalItemsInManifest;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mOpened;
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-03-31 21:29:02 -07:00
|
|
|
|
2008-11-18 11:11:35 -08:00
|
|
|
nsresult ParseManifest();
|
2012-08-22 08:56:38 -07:00
|
|
|
void ReportError(const nsACString &aFilename, int16_t errorCode);
|
2014-02-24 17:16:11 -08:00
|
|
|
nsresult LoadEntry(const nsACString &aFilename, char** aBuf,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t* aBufLen = nullptr);
|
2014-02-24 17:16:11 -08:00
|
|
|
int32_t ReadLine(const char** src);
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult ParseOneFile(const char* filebuf, int16_t aFileType);
|
2014-02-24 17:16:11 -08:00
|
|
|
nsresult VerifyEntry(nsJARManifestItem* aEntry, const char* aEntryData,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLen);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult CalculateDigest(const char* aInBuf, uint32_t aInBufLen,
|
2009-04-07 02:24:58 -07:00
|
|
|
nsCString& digest);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nsJARItem
|
|
|
|
*
|
|
|
|
* An individual JAR entry. A set of nsJARItems macthing a
|
|
|
|
* supplied pattern are returned in a nsJAREnumerator.
|
|
|
|
*/
|
|
|
|
class nsJARItem : public nsIZipEntry
|
|
|
|
{
|
|
|
|
public:
|
2013-07-18 19:23:44 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_NSIZIPENTRY
|
2014-02-24 17:16:11 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsJARItem(nsZipItem* aZipItem);
|
2007-04-23 07:21:53 -07:00
|
|
|
virtual ~nsJARItem() {}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
private:
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mSize; /* size in original file */
|
|
|
|
uint32_t mRealsize; /* inflated size */
|
|
|
|
uint32_t mCrc32;
|
2009-12-15 15:01:08 -08:00
|
|
|
PRTime mLastModTime;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t mCompression;
|
2013-10-11 09:47:15 -07:00
|
|
|
uint32_t mPermissions;
|
2014-02-24 17:16:11 -08:00
|
|
|
bool mIsDirectory;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsSynthetic;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nsJAREnumerator
|
|
|
|
*
|
2014-02-24 17:16:11 -08:00
|
|
|
* Enumerates a list of files in a zip archive
|
2007-03-22 10:30:00 -07:00
|
|
|
* (based on a pattern match in its member nsZipFind).
|
|
|
|
*/
|
2012-06-12 20:27:07 -07:00
|
|
|
class nsJAREnumerator MOZ_FINAL : public nsIUTF8StringEnumerator
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-07-18 19:23:44 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_NSIUTF8STRINGENUMERATOR
|
|
|
|
|
2014-02-24 17:16:11 -08:00
|
|
|
nsJAREnumerator(nsZipFind *aFind) : mFind(aFind), mName(nullptr) {
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(mFind, "nsJAREnumerator: Missing zipFind.");
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsZipFind *mFind;
|
2009-10-17 08:54:54 -07:00
|
|
|
const char* mName; // pointer to an name owned by mArchive -- DON'T delete
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t mNameLen;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
~nsJAREnumerator() { delete mFind; }
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#if defined(DEBUG_warren) || defined(DEBUG_jband)
|
|
|
|
#define ZIP_CACHE_HIT_RATE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class nsZipReaderCache : public nsIZipReaderCache, public nsIObserver,
|
|
|
|
public nsSupportsWeakReference
|
|
|
|
{
|
|
|
|
public:
|
2013-07-18 19:23:44 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_NSIZIPREADERCACHE
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
nsZipReaderCache();
|
|
|
|
virtual ~nsZipReaderCache();
|
|
|
|
|
|
|
|
nsresult ReleaseZip(nsJAR* reader);
|
|
|
|
|
2014-02-24 17:16:11 -08:00
|
|
|
typedef nsRefPtrHashtable<nsCStringHashKey, nsJAR> ZipsHashtable;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2014-02-24 17:16:11 -08:00
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-03-31 21:29:02 -07:00
|
|
|
mozilla::Mutex mLock;
|
2014-02-24 17:16:11 -08:00
|
|
|
uint32_t mCacheSize;
|
|
|
|
ZipsHashtable mZips;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef ZIP_CACHE_HIT_RATE
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mZipCacheLookups;
|
|
|
|
uint32_t mZipCacheHits;
|
|
|
|
uint32_t mZipCacheFlushes;
|
|
|
|
uint32_t mZipSyncMisses;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#endif /* nsJAR_h__ */
|