Security Level determines the elliptic curve used in key generation

@param securityLevel currently 256 or 384
@throws InvalidArgumentException
481381
void setSecurityLevel(final int securityLevel) throws InvalidArgumentException {
        logger.trace(format("setSecurityLevel to %d", securityLevel));

        if (securityCurveMapping.isEmpty()) {
            throw new InvalidArgumentException("Security curve mapping has no entries.");
        }

        if (!securityCurveMapping.containsKey(securityLevel)) {
            StringBuilder sb = new StringBuilder();
            String sp = "";
            for (int x : securityCurveMapping.keySet()) {
                sb.append(sp).append(x);

                sp = ", ";

            }
            throw new InvalidArgumentException(format("Illegal security level: %d. Valid values are: %s", securityLevel, sb.toString()));
        }

        String lcurveName = securityCurveMapping.get(securityLevel);

        logger.debug(format("Mapped curve strength %d to %s", securityLevel, lcurveName));

        X9ECParameters params = ECNamedCurveTable.getByName(lcurveName);
        //Check if can match curve name to requested strength.
        if (params == null) {

            InvalidArgumentException invalidArgumentException = new InvalidArgumentException(
                    format("Curve %s defined for security strength %d was not found.", curveName, securityLevel));

            logger.error(invalidArgumentException);
            throw invalidArgumentException;

        }

        curveName = lcurveName;
        this.securityLevel = securityLevel;
    }
1054919
public void setSecurityProfileTargetMappings(java.util.Collection<SecurityProfileTargetMapping> securityProfileTargetMappings) {
        if (securityProfileTargetMappings == null) {
            this.securityProfileTargetMappings = null;
            return;
        }

        this.securityProfileTargetMappings = new java.util.ArrayList<SecurityProfileTargetMapping>(securityProfileTargetMappings);
    }
918959
private int checkSecurity(String strClassResource, String strSecurityMap, int iAccessType, int iLevel)
    {
        int iAccessAllowed = Constants.ACCESS_DENIED;

        if (strSecurityMap == null)
            return iAccessAllowed;  // Denied
        if (LOGIN_REQUIRED.equalsIgnoreCase(strSecurityMap))
            return Constants.LOGIN_REQUIRED;  // Denied
        if (CREATE_USER_REQUIRED.equalsIgnoreCase(strSecurityMap))
            return Constants.CREATE_USER_REQUIRED;  // Denied
    	int startThin = strClassResource.indexOf(Constants.THIN_SUBPACKAGE, 0);
    	if (startThin != -1)	// Remove the ".thin" reference
    		strClassResource = strClassResource.substring(0, startThin) + strClassResource.substring(startThin + Constants.THIN_SUBPACKAGE.length());
        
        if (this.classMatch(strClassResource, BASE_CLASS))
            return Constants.NORMAL_RETURN;   // Allow access to all base classes
        StringTokenizer tokenizer = new StringTokenizer(strSecurityMap, TOKENS);
        try {
            while (tokenizer.hasMoreTokens())
            {
                String strClass = tokenizer.nextToken();
                String strAccess = tokenizer.nextToken();
                int iClassAccessType = Constants.READ_ACCESS;
                iClassAccessType = Integer.parseInt(strAccess);
                String strLevel = tokenizer.nextToken();
                int iClassLevel = Constants.LOGIN_USER;
                iClassLevel = Integer.parseInt(strLevel);
                
                if (this.classMatch(strClassResource, strClass))
                    if (iAccessType <= iClassAccessType)
                        if (iLevel >= iClassLevel)
                {
                    iAccessAllowed = Constants.NORMAL_RETURN;
                }
            }
        } catch (NoSuchElementException ex) {
            // Done
        } catch (NumberFormatException ex) {
            ex.printStackTrace();
        }
        
        if (("1"/*DBConstants.ANON_USER_ID*/.equals(this.getProperty(Params.USER_ID)))
                || (this.getProperty(Params.USER_ID) == null))
            if (iAccessAllowed == Constants.ACCESS_DENIED)
                iAccessAllowed = Constants.LOGIN_REQUIRED;  // For anonymous access, logging in will always get you more
        
        return iAccessAllowed;
    }
907766
private boolean setupEphemeralECDHKeys() {
        int index = -1;
        if (supportedCurves != null) {
            // if the client sent the supported curves extension, pick the
            // first one that we support;
            for (int curveId : supportedCurves.curveIds()) {
                if (SupportedEllipticCurvesExtension.isSupported(curveId)) {
                    index = curveId;
                    break;
                }
            }
            if (index < 0) {
                // no match found, cannot use this ciphersuite
                return false;
            }
        } else {
            // pick our preference
            index = SupportedEllipticCurvesExtension.DEFAULT.curveIds()[0];
        }
        String oid = SupportedEllipticCurvesExtension.getCurveOid(index);
        ecdh = new ECDHCrypt(oid, sslContext.getSecureRandom());
        return true;
    }
1025584
public boolean setProtectionLevel(int level) {
    	boolean result = false;
    	switch(level) {
    	case RtfProtection.LEVEL_NONE:
    		if(this.protectionHash == null) {
    			break;
    		}
    	case RtfProtection.LEVEL_ANNOTPROT:
    	case RtfProtection.LEVEL_FORMPROT:
    	case RtfProtection.LEVEL_REVPROT:
    	case RtfProtection.LEVEL_READPROT:
        	this.protectionLevel = level;
        	result = true;
        	break;
   		default:
    	}
    	return result;
    }
439005
public void setSecureLevel(short secureLevel) throws ClassException {
	// Security
	if (secureLevel == SECURE_CFSSL_BASIC) {
	    env.put("java.naming.security.protocol", "ssl");
	    env.put("java.naming.ldap.factory.socket", "javax.net.ssl.SSLSocketFactory");
	    ClassUtil.loadClass("com.sun.net.ssl.internal.ssl.Provider");

	    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

	}
	else if (secureLevel == SECURE_CFSSL_CLIENT_AUTH) {
	    env.put("java.naming.security.protocol", "ssl");
	    env.put("java.naming.security.authentication", "EXTERNAL");
	}
	else {
	    env.put("java.naming.security.authentication", "simple");
	    env.remove("java.naming.security.protocol");
	    env.remove("java.naming.ldap.factory.socket");
	}
    }
1357600
public void setSecurityPolicyType(com.google.api.ads.admanager.axis.v201808.SecurityPolicyType securityPolicyType) {
        this.securityPolicyType = securityPolicyType;
    }
887615
private static final int getSecurityFlags(final Map properties) {
		int securityType = 0;
		securityType = "true".equals(properties
				.get(IHtmlToPdfTransformer.PDF_ALLOW_PRINTING)) ? (securityType | PdfWriter.ALLOW_PRINTING)
				: securityType;
		securityType = "true".equals(properties
				.get(IHtmlToPdfTransformer.PDF_ALLOW_MODIFY_CONTENTS)) ? (securityType | PdfWriter.ALLOW_MODIFY_CONTENTS)
				: securityType;
		securityType = "true".equals(properties
				.get(IHtmlToPdfTransformer.PDF_ALLOW_COPY)) ? (securityType | PdfWriter.ALLOW_COPY)
				: securityType;
		securityType = "true".equals(properties
				.get(IHtmlToPdfTransformer.PDF_ALLOW_MODIFT_ANNOTATIONS)) ? (securityType | PdfWriter.ALLOW_MODIFY_ANNOTATIONS)
				: securityType;
		securityType = "true".equals(properties
				.get(IHtmlToPdfTransformer.PDF_ALLOW_FILLIN)) ? (securityType | PdfWriter.ALLOW_FILL_IN)
				: securityType;
		securityType = "true".equals(properties
				.get(IHtmlToPdfTransformer.PDF_ALLOW_SCREEN_READERS)) ? (securityType | PdfWriter.ALLOW_SCREENREADERS)
				: securityType;
		securityType = "true".equals(properties
				.get(IHtmlToPdfTransformer.PDF_ALLOW_ASSEMBLY)) ? (securityType | PdfWriter.ALLOW_ASSEMBLY)
				: securityType;
		securityType = "true".equals(properties
				.get(IHtmlToPdfTransformer.PDF_ALLOW_DEGRADED_PRINTING)) ? (securityType | PdfWriter.ALLOW_DEGRADED_PRINTING)
				: securityType;

		return securityType;
	}
485299
public void authorizeSecurityGroupRule(SecurityGroupRuleOperateRequest request) {
        checkNotNull(request, "request should not be null.");
        checkStringNotEmpty(request.getSecurityGroupId(), "securityGroupId should not be empty.");
        if (Strings.isNullOrEmpty(request.getClientToken())) {
            request.setClientToken(this.generateClientToken());
        }
        if (null == request.getRule()) {
            throw new IllegalArgumentException("request rule should not be null");
        }
        InternalRequest internalRequest = this.createRequest(request, HttpMethodName.PUT, SECURITYGROUP_PREFIX,
                request.getSecurityGroupId());
        internalRequest.addParameter("authorizeRule", null);
        internalRequest.addParameter("clientToken", request.getClientToken());
        fillPayload(internalRequest, request);
        invokeHttpClient(internalRequest, AbstractBceResponse.class);
    }
899842
private void applySecurity(final SecurityContext securityContext, boolean update) {

        // System.out.println("<< Process SecurityContext on column "+title+": "+securityContext+">>");

        // calculate accessible menu items
        filterNonPrivilegeOperations(securityContext, accessibleTopMenuItems, topMenuItems);
        filterNonPrivilegeOperations(securityContext,accessibleMenuItems, menuItems);

        // the top menu is build here
        if(!plain)
            buildTopMenu(headerMenu);

        // the row level menu is build when the celltable is filled
        // hence we need to refresh it

        toggleRowLevelTools(() -> true); // hide it
        Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
            @Override
            public void execute() {
                dataProvider.refresh();
                Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
                    @Override
                    public void execute() {
                        toggleRowLevelTools(() -> selectionModel.getSelectedObject() == null); // show when selected
                    }
                });
            }
        });

    }
479842
private void buildReverse(List<List<Vertex>> adjacencyList,
                              LinkedList<X509Certificate> certPathList)
        throws GeneralSecurityException, IOException
    {
        if (debug != null) {
            debug.println("SunCertPathBuilder.buildReverse()...");
            debug.println("SunCertPathBuilder.buildReverse() InitialPolicies: "
                + buildParams.initialPolicies());
        }

        ReverseState currentState = new ReverseState();
        /* Initialize adjacency list */
        adjacencyList.clear();
        adjacencyList.add(new LinkedList<Vertex>());

        /*
         * Perform a search using each trust anchor, until a valid
         * path is found
         */
        Iterator<TrustAnchor> iter = buildParams.trustAnchors().iterator();
        while (iter.hasNext()) {
            TrustAnchor anchor = iter.next();

            /* check if anchor satisfies target constraints */
            if (anchorIsTarget(anchor, buildParams.targetCertConstraints())) {
                this.trustAnchor = anchor;
                this.pathCompleted = true;
                this.finalPublicKey = anchor.getTrustedCert().getPublicKey();
                break;
            }

            // skip anchor if it contains a DSA key with no DSA params
            X509Certificate trustedCert = anchor.getTrustedCert();
            PublicKey pubKey = trustedCert != null ? trustedCert.getPublicKey()
                                                   : anchor.getCAPublicKey();

            if (PKIX.isDSAPublicKeyWithoutParams(pubKey)) {
                continue;
            }

            /* Initialize current state */
            currentState.initState(buildParams);
            currentState.updateState(anchor, buildParams);

            currentState.algorithmChecker = new AlgorithmChecker(anchor);
            currentState.untrustedChecker = new UntrustedChecker();
            try {
                depthFirstSearchReverse(null, currentState,
                                        new ReverseBuilder(buildParams),
                                        adjacencyList, certPathList);
            } catch (GeneralSecurityException | IOException e) {
                // continue on error if more anchors to try
                if (iter.hasNext())
                    continue;
                else
                    throw e;
            }

            // break out of loop if search is successful
            if (pathCompleted) {
                break;
            }
        }

        if (debug != null) {
            debug.println("SunCertPathBuilder.buildReverse() returned from "
                + "depthFirstSearchReverse()");
            debug.println("SunCertPathBuilder.buildReverse() "
                + "certPathList.size: " + certPathList.size());
        }
    }
976768
public com.google.appengine.v1.SecurityLevel getSecurityLevel() {
    com.google.appengine.v1.SecurityLevel result = com.google.appengine.v1.SecurityLevel.valueOf(securityLevel_);
    return result == null ? com.google.appengine.v1.SecurityLevel.UNRECOGNIZED : result;
  }
473760
public function setLogLevelThreshold(string $logLevelThreshold): void
    {
        if (! array_key_exists($logLevelThreshold, $this->logLevels)) {
            throw new InvalidArgumentException('Invalid log level. Must be one of : ' . implode(', ', array_keys($this->logLevels)));
        }

        $this->logLevelThreshold = $logLevelThreshold;
    }
1336929
public static PublicKey generatePublicKey(BigInteger modulus, BigInteger publicExponent) {
		return SecureUtil.generatePublicKey(ALGORITHM_RSA.getValue(), new RSAPublicKeySpec(modulus, publicExponent));
	}
271363
public void setSecurityGroupIds(java.util.Collection<String> securityGroupIds) {
        if (securityGroupIds == null) {
            this.securityGroupIds = null;
            return;
        }

        this.securityGroupIds = new com.amazonaws.internal.SdkInternalList<String>(securityGroupIds);
    }
289110
public static void validatePublicKey(String value, PublicKeyCrypto crypto) throws BadPublicKeyException {
        if (org.springframework.util.StringUtils.hasText(value)) {
            int open = value.indexOf("-----BEGIN PGP PUBLIC KEY BLOCK-----");
            int close = value.indexOf("-----END PGP PUBLIC KEY BLOCK-----");
            if (open < 0) {
                throw new BadPublicKeyException("PublicKeyValidator.noBeginBlock");
            }
            if (close < 0) {
                throw new BadPublicKeyException("PublicKeyValidator.noEndBlock");
            }
            if (open >= 0 && close >= 0 &&open >= close) {
                throw new BadPublicKeyException("PublicKeyValidator.wrongBlockOrder");
            }

            if (!crypto.isPublicKeyValid(value)) {
                throw new BadPublicKeyException("PublicKeyValidator.invalidKey");
            }
        }
    }
434000
private static PrivateKey privateKeyFromBigInteger(BigInteger priv) {
        if (priv == null) {
            return null;
        } else {
            try {
                return ECKeyFactory.getInstance(SpongyCastleProvider.getInstance())
                        .generatePrivate(new ECPrivateKeySpec(priv, CURVE_SPEC));
            } catch (InvalidKeySpecException ex) {
                throw new AssertionError("Assumed correct key spec statically");
            }
        }
    }