Пример #1
0
 /*
  * Create a unique mapping from codeSigner cache entries to CodeSource.
  * In theory, multiple URLs origins could map to a single locally cached
  * and shared JAR file although in practice there will be a single URL in use.
  */
 private CodeSource MapSignersToCodeSource(URL url, CodeSigner[] signers)
 {
     lock (this)
     {
         Map <CodeSigner[], CodeSource> map;
         if (url == LastURL)
         {
             map = LastURLMap;
         }
         else
         {
             map = UrlToCodeSourceMap.Get(url);
             if (map == null)
             {
                 map = new HashMap <>();
                 UrlToCodeSourceMap.Put(url, map);
             }
             LastURLMap = map;
             LastURL    = url;
         }
         CodeSource cs = map.Get(signers);
         if (cs == null)
         {
             cs = new VerifierCodeSource(Csdomain, url, signers);
             SignerToCodeSource.Put(signers, cs);
         }
         return(cs);
     }
 }
Пример #2
0
            /*
             * All VerifierCodeSource instances are constructed based on
             * singleton signerCache or signerCacheCert entries for each unique signer.
             * No CodeSigner<->Certificate[] conversion is required.
             * We use these assumptions to optimize equality comparisons.
             */
            public override bool Equals(Object obj)
            {
                if (obj == this)
                {
                    return(true);
                }
                if (obj is VerifierCodeSource)
                {
                    VerifierCodeSource that = (VerifierCodeSource)obj;

                    /*
                     * Only compare against other per-signer singletons constructed
                     * on behalf of the same JarFile instance. Otherwise, compare
                     * things the slower way.
                     */
                    if (IsSameDomain(that.Csdomain))
                    {
                        if (that.Vsigners != this.Vsigners || that.Vcerts != this.Vcerts)
                        {
                            return(false);
                        }
                        if (that.Vlocation != null)
                        {
                            return(that.Vlocation.Equals(this.Vlocation));
                        }
                        else if (this.Vlocation != null)
                        {
                            return(this.Vlocation.Equals(that.Vlocation));
                        }                         // both null
                        else
                        {
                            return(true);
                        }
                    }
                }
                return(base.Equals(obj));
            }
Пример #3
0
        /*
         * Match CodeSource to a CodeSigner[] in the signer cache.
         */
        private CodeSigner[] FindMatchingSigners(CodeSource cs)
        {
            if (cs is VerifierCodeSource)
            {
                VerifierCodeSource vcs = (VerifierCodeSource)cs;
                if (vcs.IsSameDomain(Csdomain))
                {
                    return(((VerifierCodeSource)cs).PrivateSigners);
                }
            }

            /*
             * In practice signers should always be optimized above
             * but this handles a CodeSource of any type, just in case.
             */
            CodeSource[]      sources    = MapSignersToCodeSources(cs.Location, JarCodeSigners, true);
            List <CodeSource> sourceList = new List <CodeSource>();

            for (int i = 0; i < sources.Length; i++)
            {
                sourceList.Add(sources[i]);
            }
            int j = sourceList.IndexOf(cs);

            if (j != -1)
            {
                CodeSigner[] match;
                match = ((VerifierCodeSource)sourceList.Get(j)).PrivateSigners;
                if (match == null)
                {
                    match = EmptySigner;
                }
                return(match);
            }
            return(null);
        }