100. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 9/25/2018 2:13:02 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

100.1 Files compared

# Location File Last Modified
1 build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\crypto\provider RSACipher.java Mon Jan 22 14:46:50 2018 UTC
2 build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\crypto\provider RSACipher.java Wed Sep 12 16:22:43 2018 UTC

100.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 4 940
Changed 3 6
Inserted 0 0
Removed 0 0

100.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

100.4 Active regular expressions

No regular expressions were active.

100.5 Comparison detail

  1   /*
  2    * Copyrig ht (c) 200 3, 2015, O racle and/ or its aff iliates. A ll rights  reserved.
  3    * DO NOT  ALTER OR R EMOVE COPY RIGHT NOTI CES OR THI S FILE HEA DER.
  4    *
  5    * This co de is free  software;  you can r edistribut e it and/o r modify i t
  6    * under t he terms o f the GNU  General Pu blic Licen se version  2 only, a s
  7    * publish ed by the  Free Softw are Founda tion.  Ora cle design ates this
  8    * particu lar file a s subject  to the "Cl asspath" e xception a s provided
  9    * by Orac le in the  LICENSE fi le that ac companied  this code.
  10    *
  11    * This co de is dist ributed in  the hope  that it wi ll be usef ul, but WI THOUT
  12    * ANY WAR RANTY; wit hout even  the implie d warranty  of MERCHA NTABILITY  or
  13    * FITNESS  FOR A PAR TICULAR PU RPOSE.  Se e the GNU  General Pu blic Licen se
  14    * version  2 for mor e details  (a copy is  included  in the LIC ENSE file  that
  15    * accompa nied this  code).
  16    *
  17    * You sho uld have r eceived a  copy of th e GNU Gene ral Public  License v ersion
  18    * 2 along  with this  work; if  not, write  to the Fr ee Softwar e Foundati on,
  19    * Inc., 5 1 Franklin  St, Fifth  Floor, Bo ston, MA 0 2110-1301  USA.
  20    *
  21    * Please  contact Or acle, 500  Oracle Par kway, Redw ood Shores , CA 94065  USA
  22    * or visi t www.orac le.com if  you need a dditional  informatio n or have  any
  23    * questio ns.
  24    */
  25  
  26   package co m.sun.cryp to.provide r;
  27  
  28   import jav a.util.Loc ale;
  29  
  30   import jav a.security .*;
  31   import jav a.security .interface s.*;
  32   import jav a.security .spec.Algo rithmParam eterSpec;
  33   import jav a.security .spec.Inva lidParamet erSpecExce ption;
  34   import jav a.security .spec.MGF1 ParameterS pec;
  35  
  36   import jav ax.crypto. *;
  37   import jav ax.crypto. spec.PSour ce;
  38   import jav ax.crypto. spec.OAEPP arameterSp ec;
  39  
  40   import sun .security. rsa.*;
  41   import sun .security. jca.Provid ers;
  42   import sun .security. internal.s pec.TlsRsa PremasterS ecretParam eterSpec;
  43   import sun .security. util.KeyUt il;
  44  
  45   /**
  46    * RSA cip her implem entation.  Supports R SA en/decr yption and  signing/v erifying
  47    * using P KCS#1 v1.5  padding a nd without  padding ( raw RSA).  Note that  raw RSA
  48    * is supp orted most ly for com pleteness  and should  only be u sed in rar e cases.
  49    *
  50    * Objects  should be  instantia ted by cal ling Ciphe r.getInsta nce() usin g the
  51    * followi ng algorit hm names:
  52    *  . "RSA /ECB/PKCS1 Padding" ( or "RSA")  for PKCS#1  padding.  The mode ( blocktype)
  53    *    is s elected ba sed on the  en/decryp tion mode  and public /private k ey used
  54    *  . "RSA /ECB/NoPad ding" for  rsa RSA.
  55    *
  56    * We only  do one RS A operatio n per doFi nal() call . If the a pplication  passes
  57    * more da ta via cal ls to upda te() or do Final(), w e throw an
  58    * Illegal BlockSizeE xception w hen doFina l() is cal led (see J CE API spe c).
  59    * Bulk en cryption u sing RSA d oes not ma ke sense a nd is not  standardiz ed.
  60    *
  61    * Note: R SA keys sh ould be at  least 512  bits long
  62    *
  63    * @since    1.5
  64    * @author   Andreas  Sterbenz
  65    */
  66   public fin al class R SACipher e xtends Cip herSpi {
  67  
  68       // con stant for  an empty b yte array
  69       privat e final st atic byte[ ] B0 = new  byte[0];
  70  
  71       // mod e constant  for publi c key encr yption
  72       privat e final st atic int M ODE_ENCRYP T = 1;
  73       // mod e constant  for priva te key dec ryption
  74       privat e final st atic int M ODE_DECRYP T = 2;
  75       // mod e constant  for priva te key enc ryption (s igning)
  76       privat e final st atic int M ODE_SIGN     = 3;
  77       // mod e constant  for publi c key decr yption (ve rifying)
  78       privat e final st atic int M ODE_VERIFY   = 4;
  79  
  80       // con stant for  raw RSA
  81       privat e final st atic Strin g PAD_NONE   = "NoPad ding";
  82       // con stant for  PKCS#1 v1. 5 RSA
  83       privat e final st atic Strin g PAD_PKCS 1 = "PKCS1 Padding";
  84       // con stant for  PKCS#2 v2. 0 OAEP wit h MGF1
  85       privat e final st atic Strin g PAD_OAEP _MGF1  = " OAEP";
  86  
  87       // cur rent mode,  one of MO DE_* above . Set when  init() is  called
  88       privat e int mode ;
  89  
  90       // act ive paddin g type, on e of PAD_*  above. Se t by setPa dding()
  91       privat e String p addingType ;
  92  
  93       // pad ding objec t
  94       privat e RSAPaddi ng padding ;
  95  
  96         // cipher  parameter  for OAEP p adding and  TLS RSA p remaster  PW     
  97       privat e Algorith mParameter Spec spec  = null;
  98  
  99       // buf fer for th e data
  100       privat e byte[] b uffer;
  101       // off set into t he buffer  (number of  bytes buf fered)
  102       privat e int bufO fs;
  103  
  104       // siz e of the o utput
  105       privat e int outp utSize;
  106  
  107       // the  public ke y, if we w ere initia lized usin g a public  key
  108       privat e RSAPubli cKey publi cKey;
  109       // the  private k ey, if we  were initi alized usi ng a priva te key
  110       privat e RSAPriva teKey priv ateKey;
  111  
  112       // has h algorith m for OAEP
  113       privat e String o aepHashAlg orithm = " SHA-1";
  114  
  115       // the  source of  randomnes s
  116       privat e SecureRa ndom rando m;
  117  
  118       public  RSACipher () {
  119           pa ddingType  = PAD_PKCS 1;
  120       }
  121  
  122       // mod es do not  make sense  for RSA,  but allow  ECB
  123       // see  JCE spec
  124       protec ted void e ngineSetMo de(String  mode) thro ws NoSuchA lgorithmEx ception {
  125           if  (mode.equ alsIgnoreC ase("ECB")  == false)  {
  126                throw ne w NoSuchAl gorithmExc eption("Un supported  mode " + m ode);
  127           }
  128       }
  129  
  130       // set  the paddi ng type
  131       // see  JCE spec
  132       protec ted void e ngineSetPa dding(Stri ng padding Name)
  133                throws N oSuchPaddi ngExceptio n {
  134           if  (paddingN ame.equals IgnoreCase (PAD_NONE) ) {
  135                paddingT ype = PAD_ NONE;
  136           }  else if (p addingName .equalsIgn oreCase(PA D_PKCS1))  {
  137                paddingT ype = PAD_ PKCS1;
  138           }  else {
  139                String l owerPaddin g = paddin gName.toLo werCase(Lo cale.ENGLI SH);
  140                if (lowe rPadding.e quals("oae ppadding") ) {
  141                    padd ingType =  PAD_OAEP_M GF1;
  142                } else i f (lowerPa dding.star tsWith("oa epwith") & &
  143                            lowerPa dding.ends With("andm gf1padding ")) {
  144                    padd ingType =  PAD_OAEP_M GF1;
  145                    // " oaepwith". length() = = 8
  146                    // " andmgf1pad ding".leng th() == 14
  147                    oaep HashAlgori thm =
  148                             paddin gName.subs tring(8, p addingName .length()  - 14);
  149                    // c heck if Me ssageDiges t appears  to be avai lable
  150                    // a void getIn stance() c all here
  151                    if ( Providers. getProvide rList().ge tService
  152                             ("Mess ageDigest" , oaepHash Algorithm)  == null)  {
  153                         throw new  NoSuchPadd ingExcepti on
  154                             ("Mess ageDigest  not availa ble for "  + paddingN ame);
  155                    }
  156                } else {
  157                    thro w new NoSu chPaddingE xception
  158                         ("Padding  " + paddin gName + "  not suppor ted");
  159                }
  160           }
  161       }
  162  
  163       // ret urn 0 as b lock size,  we are no t a block  cipher
  164       // see  JCE spec
  165       protec ted int en gineGetBlo ckSize() {
  166           re turn 0;
  167       }
  168  
  169       // ret urn the ou tput size
  170       // see  JCE spec
  171       protec ted int en gineGetOut putSize(in t inputLen ) {
  172           re turn outpu tSize;
  173       }
  174  
  175       // no  iv, return  null
  176       // see  JCE spec
  177       protec ted byte[]  engineGet IV() {
  178           re turn null;
  179       }
  180  
  181       // see  JCE spec
  182       protec ted Algori thmParamet ers engine GetParamet ers() {
  183           if  (spec !=  null && sp ec instanc eof OAEPPa rameterSpe c) {
  184                try {
  185                    Algo rithmParam eters para ms =
  186                         AlgorithmP arameters. getInstanc e("OAEP",
  187                             SunJCE .getInstan ce());
  188                    para ms.init(sp ec);
  189                    retu rn params;
  190                } catch  (NoSuchAlg orithmExce ption nsae ) {
  191                    // s hould neve r happen
  192                    thro w new Runt imeExcepti on("Cannot  find OAEP  " +
  193                         " Algorith mParameter s implemen tation in  SunJCE pro vider");
  194                } catch  (InvalidPa rameterSpe cException  ipse) {
  195                    // s hould neve r happen
  196                    thro w new Runt imeExcepti on("OAEPPa rameterSpe c not supp orted");
  197                }
  198           }  else {
  199                return n ull;
  200           }
  201       }
  202  
  203       // see  JCE spec
  204       protec ted void e ngineInit( int opmode , Key key,  SecureRan dom random )
  205                throws I nvalidKeyE xception {
  206           tr y {
  207                init(opm ode, key,  random, nu ll);
  208           }  catch (Inv alidAlgori thmParamet erExceptio n iape) {
  209                // never  thrown wh en null pa rameters a re used;
  210                // but r e-throw it  just in c ase
  211                InvalidK eyExceptio n ike =
  212                    new  InvalidKey Exception( "Wrong par ameters");
  213                ike.init Cause(iape );
  214                throw ik e;
  215           }
  216       }
  217  
  218       // see  JCE spec
  219       protec ted void e ngineInit( int opmode , Key key,
  220                Algorith mParameter Spec param s, SecureR andom rand om)
  221                throws I nvalidKeyE xception,  InvalidAlg orithmPara meterExcep tion {
  222           in it(opmode,  key, rand om, params );
  223       }
  224  
  225       // see  JCE spec
  226       protec ted void e ngineInit( int opmode , Key key,
  227                Algorith mParameter s params,  SecureRand om random)
  228                throws I nvalidKeyE xception,  InvalidAlg orithmPara meterExcep tion {
  229           if  (params = = null) {
  230                init(opm ode, key,  random, nu ll);
  231           }  else {
  232                try {
  233                    OAEP ParameterS pec spec =
  234                             params .getParame terSpec(OA EPParamete rSpec.clas s);
  235                    init (opmode, k ey, random , spec);
  236                } catch  (InvalidPa rameterSpe cException  ipse) {
  237                    Inva lidAlgorit hmParamete rException  iape =
  238                         new Invali dAlgorithm ParameterE xception(" Wrong para meter");
  239                    iape .initCause (ipse);
  240                    thro w iape;
  241                }
  242           }
  243       }
  244  
  245       // ini tialize th is cipher
  246       privat e void ini t(int opmo de, Key ke y, SecureR andom rand om,
  247                Algorith mParameter Spec param s)
  248                throws I nvalidKeyE xception,  InvalidAlg orithmPara meterExcep tion {
  249           bo olean encr ypt;
  250           sw itch (opmo de) {
  251           ca se Cipher. ENCRYPT_MO DE:
  252           ca se Cipher. WRAP_MODE:
  253                encrypt  = true;
  254                break;
  255           ca se Cipher. DECRYPT_MO DE:
  256           ca se Cipher. UNWRAP_MOD E:
  257                encrypt  = false;
  258                break;
  259           de fault:
  260                throw ne w InvalidK eyExceptio n("Unknown  mode: " +  opmode);
  261           }
  262           RS AKey rsaKe y = RSAKey Factory.to RSAKey(key );
  263           if  (key inst anceof RSA PublicKey)  {
  264                mode = e ncrypt ? M ODE_ENCRYP T : MODE_V ERIFY;
  265                publicKe y = (RSAPu blicKey)ke y;
  266                privateK ey = null;
  267           }  else { //  must be RS APrivateKe y per chec k in toRSA Key
  268                mode = e ncrypt ? M ODE_SIGN :  MODE_DECR YPT;
  269                privateK ey = (RSAP rivateKey) key;
  270                publicKe y = null;
  271           }
  272           in t n = RSAC ore.getByt eLength(rs aKey.getMo dulus());
  273           ou tputSize =  n;
  274           bu fOfs = 0;
  275           if  (paddingT ype == PAD _NONE) {
  276                if (para ms != null ) {
  277                    thro w new Inva lidAlgorit hmParamete rException
  278                    ("Pa rameters n ot support ed");
  279                }
  280                padding  = RSAPaddi ng.getInst ance(RSAPa dding.PAD_ NONE, n, r andom);
  281                buffer =  new byte[ n];
  282           }  else if (p addingType  == PAD_PK CS1) {
  283                if (para ms != null ) {
  284                    if ( !(params i nstanceof  TlsRsaPrem asterSecre tParameter Spec)) {
  285                         throw new  InvalidAlg orithmPara meterExcep tion(
  286                                 "P arameters  not suppor ted");
  287                    }
  288  
  289                    spec  = params;
  290                      this.rando m = random    // for TLS  RSA prema ster  PW     
  291                }
  292                int bloc kType = (m ode <= MOD E_DECRYPT)  ? RSAPadd ing.PAD_BL OCKTYPE_2
  293                                                           : RSAPadd ing.PAD_BL OCKTYPE_1;
  294                padding  = RSAPaddi ng.getInst ance(block Type, n, r andom);
  295                if (encr ypt) {
  296                    int  k = paddin g.getMaxDa taSize();
  297                    buff er = new b yte[k];
  298                } else {
  299                    buff er = new b yte[n];
  300                }
  301           }  else { //  PAD_OAEP_M GF1
  302                if ((mod e == MODE_ SIGN) || ( mode == MO DE_VERIFY) ) {
  303                    thro w new Inva lidKeyExce ption
  304                             ("OAEP  cannot be  used to s ign or ver ify signat ures");
  305                }
  306                if (para ms != null ) {
  307                    if ( !(params i nstanceof  OAEPParame terSpec))  {
  308                         throw new  InvalidAlg orithmPara meterExcep tion
  309                             ("Wron g Paramete rs for OAE P Padding" );
  310                    }
  311                    spec  = params;
  312                } else {
  313                    spec  = new OAE PParameter Spec(oaepH ashAlgorit hm, "MGF1" ,
  314                         MGF1Parame terSpec.SH A1, PSourc e.PSpecifi ed.DEFAULT );
  315                }
  316                padding  = RSAPaddi ng.getInst ance(RSAPa dding.PAD_ OAEP_MGF1,  n,
  317                    rand om, (OAEPP arameterSp ec)spec);
  318                if (encr ypt) {
  319                    int  k = paddin g.getMaxDa taSize();
  320                    buff er = new b yte[k];
  321                } else {
  322                    buff er = new b yte[n];
  323                }
  324           }
  325       }
  326  
  327       // int ernal upda te method
  328       privat e void upd ate(byte[]  in, int i nOfs, int  inLen) {
  329           if  ((inLen = = 0) || (i n == null) ) {
  330                return;
  331           }
  332           if  (bufOfs +  inLen > b uffer.leng th) {
  333                bufOfs =  buffer.le ngth + 1;
  334                return;
  335           }
  336           Sy stem.array copy(in, i nOfs, buff er, bufOfs , inLen);
  337           bu fOfs += in Len;
  338       }
  339  
  340       // int ernal doFi nal() meth od. Here w e perform  the actual  RSA opera tion
  341       privat e byte[] d oFinal() t hrows BadP addingExce ption,
  342                IllegalB lockSizeEx ception {
  343           if  (bufOfs >  buffer.le ngth) {
  344                throw ne w IllegalB lockSizeEx ception("D ata must n ot be long er "
  345                    + "t han " + bu ffer.lengt h + " byte s");
  346           }
  347           tr y {
  348                byte[] d ata;
  349                switch ( mode) {
  350                case MOD E_SIGN:
  351                    data  = padding .pad(buffe r, 0, bufO fs);
  352                    retu rn RSACore .rsa(data,  privateKe y, true);
  353                case MOD E_VERIFY:
  354                    byte [] verifyB uffer = RS ACore.conv ert(buffer , 0, bufOf s);
  355                    data  = RSACore .rsa(verif yBuffer, p ublicKey);
  356                    retu rn padding .unpad(dat a);
  357                case MOD E_ENCRYPT:
  358                    data  = padding .pad(buffe r, 0, bufO fs);
  359                    retu rn RSACore .rsa(data,  publicKey );
  360                case MOD E_DECRYPT:
  361                    byte [] decrypt Buffer = R SACore.con vert(buffe r, 0, bufO fs);
  362                    data  = RSACore .rsa(decry ptBuffer,  privateKey , false);
  363                    retu rn padding .unpad(dat a);
  364                default:
  365                    thro w new Asse rtionError ("Internal  error");
  366                }
  367           }  finally {
  368                bufOfs =  0;
  369           }
  370       }
  371  
  372       // see  JCE spec
  373       protec ted byte[]  engineUpd ate(byte[]  in, int i nOfs, int  inLen) {
  374           up date(in, i nOfs, inLe n);
  375           re turn B0;
  376       }
  377  
  378       // see  JCE spec
  379       protec ted int en gineUpdate (byte[] in , int inOf s, int inL en, byte[]  out,
  380                int outO fs) {
  381           up date(in, i nOfs, inLe n);
  382           re turn 0;
  383       }
  384  
  385       // see  JCE spec
  386       protec ted byte[]  engineDoF inal(byte[ ] in, int  inOfs, int  inLen)
  387                throws B adPaddingE xception,  IllegalBlo ckSizeExce ption {
  388           up date(in, i nOfs, inLe n);
  389           re turn doFin al();
  390       }
  391  
  392       // see  JCE spec
  393       protec ted int en gineDoFina l(byte[] i n, int inO fs, int in Len, byte[ ] out,
  394                int outO fs) throws  ShortBuff erExceptio n, BadPadd ingExcepti on,
  395                IllegalB lockSizeEx ception {
  396           if  (outputSi ze > out.l ength - ou tOfs) {
  397                throw ne w ShortBuf ferExcepti on
  398                    ("Ne ed " + out putSize +  " bytes fo r output") ;
  399           }
  400           up date(in, i nOfs, inLe n);
  401           by te[] resul t = doFina l();
  402           in t n = resu lt.length;
  403           Sy stem.array copy(resul t, 0, out,  outOfs, n );
  404           re turn n;
  405       }
  406  
  407       // see  JCE spec
  408       protec ted byte[]  engineWra p(Key key)  throws In validKeyEx ception,
  409                IllegalB lockSizeEx ception {
  410           by te[] encod ed = key.g etEncoded( );
  411           if  ((encoded  == null)  || (encode d.length = = 0)) {
  412                throw ne w InvalidK eyExceptio n("Could n ot obtain  encoded ke y");
  413           }
  414           if  (encoded. length > b uffer.leng th) {
  415                throw ne w InvalidK eyExceptio n("Key is  too long f or wrappin g");
  416           }
  417           up date(encod ed, 0, enc oded.lengt h);
  418           tr y {
  419                return d oFinal();
  420           }  catch (Bad PaddingExc eption e)  {
  421                // shoul d not occu r
  422                throw ne w InvalidK eyExceptio n("Wrappin g failed",  e);
  423           }
  424       }
  425  
  426       // see  JCE spec
  427       protec ted Key en gineUnwrap (byte[] wr appedKey,  String alg orithm,
  428                int type ) throws I nvalidKeyE xception,  NoSuchAlgo rithmExcep tion {
  429           if  (wrappedK ey.length  > buffer.l ength) {
  430                throw ne w InvalidK eyExceptio n("Key is  too long f or unwrapp ing");
  431           }
  432  
  433           bo olean isTl sRsaPremas terSecret  =
  434                    algo rithm.equa ls("TlsRsa PremasterS ecret");
  435           Ex ception fa ilover = n ull;
  436           by te[] encod ed = null;
  437  
  438           up date(wrapp edKey, 0,  wrappedKey .length);
  439           tr y {
  440                encoded  = doFinal( );
  441           }  catch (Bad PaddingExc eption e)  {
  442                if (isTl sRsaPremas terSecret)  {
  443                    fail over = e;
  444                } else {
  445                    thro w new Inva lidKeyExce ption("Unw rapping fa iled", e);
  446                }
  447           }  catch (Ill egalBlockS izeExcepti on e) {
  448                // shoul d not occu r, handled  with leng th check a bove
  449                throw ne w InvalidK eyExceptio n("Unwrapp ing failed ", e);
  450           }
  451  
  452           if  (isTlsRsa PremasterS ecret) {
  453                if (!(sp ec instanc eof TlsRsa PremasterS ecretParam eterSpec))  {
  454                    thro w new Ille galStateEx ception(
  455                             "No Tl sRsaPremas terSecretP arameterSp ec specifi ed");
  456                }
  457  
  458                  // polish  the TLS pr emaster  PW     
  459                encoded  = KeyUtil. checkTlsPr eMasterSec retKey(
  460                    ((Tl sRsaPremas terSecretP arameterSp ec)spec).g etClientVe rsion(),
  461                    ((Tl sRsaPremas terSecretP arameterSp ec)spec).g etServerVe rsion(),
  462                    rand om, encode d, (failov er != null ));
  463           }
  464  
  465           re turn Const ructKeys.c onstructKe y(encoded,  algorithm , type);
  466       }
  467  
  468       // see  JCE spec
  469       protec ted int en gineGetKey Size(Key k ey) throws  InvalidKe yException  {
  470           RS AKey rsaKe y = RSAKey Factory.to RSAKey(key );
  471           re turn rsaKe y.getModul us().bitLe ngth();
  472       }
  473   }